Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to construct HFIDs from payload for upsert mutations #4339

Merged
merged 1 commit into from
Sep 18, 2024

Conversation

ogenstad
Copy link
Contributor

@ogenstad ogenstad commented Sep 12, 2024

This adds to the MutationNodeGetterByHfid class so that it attempts to construct an HFID based on the payload of the mutation. This is done by looking at how the HFID for the object should be constructed and then see if we have enough information within the payload to create an HFID.

I've not looked too closely at the HFIDs before the implementation here is done with the assumption that there are two kinds of HFID components

  • attributes: based on the name of the attribute and the property to look at i.e. name__value
  • relationships: as attributes but prefixed by the name of the relationship i.e. device__name__value

I've also changed the SDK so that it doesn't attempt to send in hfid if any of the fields are missing. The current behaviour was to convert the None value into the string "None". I don't know if there is a scenario where we actually want part of the htid to be the string "None", but that part seems wrong.

Fixes opsmill/infrahub-sdk-python#45

@ogenstad ogenstad added the type/feature New feature or request label Sep 12, 2024
@github-actions github-actions bot added group/backend Issue related to the backend (API Server, Git Agent) group/python-sdk labels Sep 12, 2024
@ogenstad ogenstad force-pushed the pog-construct-upsert-hfid-IFC-567 branch 3 times, most recently from 4abbc06 to f19d60a Compare September 12, 2024 12:12
@ogenstad ogenstad marked this pull request as ready for review September 16, 2024 13:05
@ogenstad ogenstad requested a review from a team September 16, 2024 13:06

hfid: list[str] = []
for component in node_schema.human_friendly_id:
name, hfid_value = component.split("__", maxsplit=1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could use node_schema.parse_schema_path here to get a SchemaAttributePath that includes the relationship schema, related schema, attribute_schema, and attribute_property_name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added this and also removed the initial data.get(). All good with the changes now?

@ogenstad ogenstad force-pushed the pog-construct-upsert-hfid-IFC-567 branch from f19d60a to 573efc2 Compare September 18, 2024 06:06
@ogenstad ogenstad force-pushed the pog-construct-upsert-hfid-IFC-567 branch from 573efc2 to 7a23193 Compare September 18, 2024 06:55
@ogenstad ogenstad merged commit a0593b5 into stable Sep 18, 2024
45 checks passed
@ogenstad ogenstad deleted the pog-construct-upsert-hfid-IFC-567 branch September 18, 2024 14:44
dgarros added a commit to opsmill/infrahub-sdk-python that referenced this pull request Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
group/backend Issue related to the backend (API Server, Git Agent) type/feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants