Add allow_upsert option to LineDelimitedJSONImporter#765
Add allow_upsert option to LineDelimitedJSONImporter#765
Conversation
WalkthroughThis pull request wires a new boolean 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Deploying infrahub-sdk-python with
|
| Latest commit: |
072eeb6
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://43c83d6a.infrahub-sdk-python.pages.dev |
| Branch Preview URL: | https://atg-20260122-ctl-load.infrahub-sdk-python.pages.dev |
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## stable #765 +/- ##
==========================================
- Coverage 80.77% 72.93% -7.85%
==========================================
Files 132 119 -13
Lines 10999 10340 -659
Branches 1681 1552 -129
==========================================
- Hits 8884 7541 -1343
- Misses 1566 2285 +719
+ Partials 549 514 -35
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 42 files with indirect coverage changes 🚀 New features to boost your workflow:
|
…n; enhance handling of RelatedNode inputs
ce6441e to
f0e0140
Compare
There was a problem hiding this comment.
3 issues found across 9 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="docs/docs/infrahubctl/infrahubctl-load.mdx">
<violation number="1" location="docs/docs/infrahubctl/infrahubctl-load.mdx:20">
P3: Don't hand-edit this generated CLI doc; update the source definition and regenerate the MDX instead.</violation>
</file>
<file name="infrahub_sdk/transfer/exporter/json.py">
<violation number="1" location="infrahub_sdk/transfer/exporter/json.py:56">
P1: This now exports one-way `many` relationships into `relationships.json`, but the importer treats that file as many-to-many-only and reapplies links, causing duplicate relationship updates.</violation>
</file>
<file name="infrahub_sdk/node/related_node.py">
<violation number="1" location="infrahub_sdk/node/related_node.py:52">
P2: Preserve `kind` when reusing an existing RelatedNode; otherwise HFID-backed references lose identifying data.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| # Record the relationship only if it's not known in one way or another | ||
| # This avoids duplicating bidirectional many-to-many relationships | ||
| if not forward and not backward: | ||
| many_relationship_identifiers[node_schema.kind, relationship.peer] = relationship.identifier |
There was a problem hiding this comment.
P1: This now exports one-way many relationships into relationships.json, but the importer treats that file as many-to-many-only and reapplies links, causing duplicate relationship updates.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At infrahub_sdk/transfer/exporter/json.py, line 56:
<comment>This now exports one-way `many` relationships into `relationships.json`, but the importer treats that file as many-to-many-only and reapplies links, causing duplicate relationship updates.</comment>
<file context>
@@ -34,31 +34,26 @@ def wrapped_task_output(self, start: str, end: str = "[green]done") -> Generator
+ # Record the relationship only if it's not known in one way or another
+ # This avoids duplicating bidirectional many-to-many relationships
+ if not forward and not backward:
+ many_relationship_identifiers[node_schema.kind, relationship.peer] = relationship.identifier
return many_relationship_identifiers
</file context>
| many_relationship_identifiers[node_schema.kind, relationship.peer] = relationship.identifier | |
| has_many_peer = any( | |
| peer_relationship.cardinality == "many" and peer_relationship.peer == node_schema.kind | |
| for peer_relationship in node_schema_map[relationship.peer].relationships | |
| ) | |
| if has_many_peer: | |
| many_relationship_identifiers[node_schema.kind, relationship.peer] = relationship.identifier |
| elif isinstance(data, RelatedNodeBase): | ||
| # Handle when value is already a RelatedNode - extract its identifying data | ||
| data = {"id": data.id, "hfid": data.hfid, "__typename": data.typename} |
There was a problem hiding this comment.
P2: Preserve kind when reusing an existing RelatedNode; otherwise HFID-backed references lose identifying data.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At infrahub_sdk/node/related_node.py, line 52:
<comment>Preserve `kind` when reusing an existing RelatedNode; otherwise HFID-backed references lose identifying data.</comment>
<file context>
@@ -49,6 +49,10 @@ def __init__(self, branch: str, schema: RelationshipSchemaAPI, data: Any | dict,
setattr(self, prop, None)
self._relationship_metadata = None
+ elif isinstance(data, RelatedNodeBase):
+ # Handle when value is already a RelatedNode - extract its identifying data
+ data = {"id": data.id, "hfid": data.hfid, "__typename": data.typename}
</file context>
| elif isinstance(data, RelatedNodeBase): | |
| # Handle when value is already a RelatedNode - extract its identifying data | |
| data = {"id": data.id, "hfid": data.hfid, "__typename": data.typename} | |
| elif isinstance(data, RelatedNodeBase): | |
| # Handle when value is already a RelatedNode - extract its identifying data | |
| data = {"id": data.id, "hfid": data.hfid, "kind": data.kind, "__typename": data.typename} |
| @@ -17,6 +17,7 @@ $ infrahubctl load [OPTIONS] | |||
| * `--branch TEXT`: Branch from which to export | |||
There was a problem hiding this comment.
P3: Don't hand-edit this generated CLI doc; update the source definition and regenerate the MDX instead.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At docs/docs/infrahubctl/infrahubctl-load.mdx, line 20:
<comment>Don't hand-edit this generated CLI doc; update the source definition and regenerate the MDX instead.</comment>
<file context>
@@ -17,6 +17,7 @@ $ infrahubctl load [OPTIONS]
* `--branch TEXT`: Branch from which to export
* `--concurrent INTEGER`: Maximum number of requests to execute at the same time. [env var: INFRAHUB_MAX_CONCURRENT_EXECUTION]
* `--timeout INTEGER`: Timeout in sec [env var: INFRAHUB_TIMEOUT; default: 60]
+* `--allow-upsert / --no-allow-upsert`: Use Upsert mutations instead of Create. Use when objects may already exist. [default: no-allow-upsert]
* `--install-completion`: Install completion for the current shell.
* `--show-completion`: Show completion for the current shell, to copy it or customize the installation.
</file context>
…n; enhance handling of RelatedNode inputsAdd allow_upsert option to LineDelimitedJSONImporter and load function; enhance handling of RelatedNode inputs
Summary by CodeRabbit
New Features
Improvements
Tests
✏️ Tip: You can customize this high-level summary in your review settings.