Skip to content

Why is nullable filtered out? #36

@Gunni

Description

@Gunni

I am talking with a varlink service, one of its fields is type ?int when the api returns a payload where this value is null then the python code filters it out, I tracked it down to this block of code:

if ret != None:

I'm just trying to understand.

  1. Why is a null field in a struct not propagated to a client
  2. How can a client discover all fields and create a valid instance of the object if it doesn't get to know all the fields.
  3. If it's being sent to the client then it can't be about saving traffic, so why filter it out?

f.ex:

import varlink
with varlink.Client('unix:/tmp/test.sock') as client, client.open('com.example.network') as c:
	n = c.Get()
	print(type(n))
	print(n)

Where the interface is:

interface com.example.network

type NetworkSettings (
	...
	ETH1VLAN_VLAN: ?int,
	ETH1VLAN_CIDR_V4: []string,
	ETH1VLAN_CIDR_V6: []string,
	...
)

method Get() -> (settings: NetworkSettings)
method Set(settings: NetworkSettings) -> ()
method Validate(settings: NetworkSettings) -> ()

I get:

<class 'dict'>
{'settings': {... 'ETH1VLAN_CIDR_V4': [], 'ETH1VLAN_CIDR_V6': [], ...}}

If the value for ETH1VLAN_VLAN is null then the client gets it but filters it out, meaning I cannot discover the key ETH1VLAN_VLAN. If I want to print out the dict I got back, it's not even type NetworkSettings, it's just a plain dict...

Am I using this wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions