Skip to content

bug: querying a node multiple times might lead to missing information in the store #413

Description

@wvandeun

Component

No response

Infrahub SDK version

1.12.1

Current Behavior

When you query a multiple nodes, might lead to unexpected state of the node in the SDK store.

For example relationship information that you initially queried, and therefor was stored in store, might not be available anymore after you query the node for a second time.

client = InfrahubClientSync(address="https://demo.infrahub.app/")

interface = client.get("InfraInterface", device__name__value="jfk1-edge1", name__value="Ethernet6", prefetch_relationships=True)
client.store.get(interface.id).device.id

client.all("InfraCircuitEndpoint", prefetch_relationships=True)
client.store.get(interface.id).device.id

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'id'

In this example We initially queried an interface and it's related nodes. We can access the interface object from the store, as well as the related node for the device relationship.

Later, we want to fetch all circuit endpoint objects and its related nodes. The interfaces connected to this circuit endpoint will be retrieved and stored in the store. In the 2nd query will not include the device relationship of the interface, which leads to the fact that this information is now inaccessible from the store.

Also after the 2nd query, it seems that the node is stored in the store twice, once with the relationship information from the first query, a second time without the relationship information from the 2nd query).

The UUIDs map in the store will now point to the object as it was retrieved in the last query.

(see Ethernet6)

pp(client.store._branches["main"]._objs)
{'7hz76yp6rwwsi1klbgzofw': InfraCircuitEndpoint(ID: 1808d346-b3b7-821a-d0e8-c513dfa8921c),
 '_kllszzqqcmpqye_nvct_g': Ethernet6,
 'dkvc79gftvoakc55dhf-rq': DUFF-1022b0282c8e,
 'sim5eml0r6sdddrxx9kpnq': jfk1-edge1,
 'skmnaxluqguzqol5itsckw': jfk1,
 'vz-kuwxqrq-crxxszqfoiw': Ethernet6}

pp(client.store._branches["main"]._uuids)
{'1808d343-5d29-d8b8-d0e5-c51ee0325110': 'skmnaxluqguzqol5itsckw',
 '1808d344-74d9-9abd-d0e5-c513af38cc50': 'sim5eml0r6sdddrxx9kpnq',
 '1808d346-6544-424d-d0ee-c51b75b9408c': '_kllszzqqcmpqye_nvct_g',
 '1808d346-a739-79a7-d0eb-c518554ee145': 'dkvc79gftvoakc55dhf-rq',
 '1808d346-b3b7-821a-d0e8-c513dfa8921c': '7hz76yp6rwwsi1klbgzofw'}

Expected Behavior

Ideally the previously fetched relationship information would still be accessible after a node gets queried a next time (maybe even unintentionally).

Maybe we should not store a node that gets fetched as related node in the store again, if it is already stored in the store?

Steps to Reproduce

See current behavior

Additional Information

No response

Metadata

Metadata

Assignees

Labels

priority/2This issue stalls work on the project or its dependents, it's a blocker for a releasestate/need-triageThis issue needs to be triagedtype/bugSomething isn't working as expected

Type

Fields

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions