Skip to content

IFC-1238: Fix failure when removing generic attribute and its uniqueness constraint#9288

Open
solababs wants to merge 2 commits into
stablefrom
fix-generic-uniqueness-ifc-1238
Open

IFC-1238: Fix failure when removing generic attribute and its uniqueness constraint#9288
solababs wants to merge 2 commits into
stablefrom
fix-generic-uniqueness-ifc-1238

Conversation

@solababs
Copy link
Copy Markdown
Contributor

@solababs solababs commented May 19, 2026

Why

When an attribute and its uniqueness_constraints entry are removed from a generic schema in a single update, the schema reload raises a 500 Internal Server Error. The error is:

ValueError: TestMyGeneric: Requested unique constraint not found within node. (`identifier__value`)

Root cause: process_attributes_state() removes ABSENT attributes from the schema object but leaves stale paths in uniqueness_constraints. The immediately following sync_uniqueness_constraints_and_unique_attributes() then calls parse_schema_path() on a path whose attribute no longer exists, triggering AttributePathParsingError. The same operation works for regular node schemas and succeeds when split into two sequential updates.

Closes #5735

How to test

uv run pytest backend/tests/integration/schema_lifecycle/test_migration_uniqueness_constraints.py -v -k "TestGenericRemoveAttributesAndConstraints"

Checklist

  • Tests added/updated
  • Changelog entry added (changelog/5735.fixed.md)
  • External docs updated (if user-facing or ops-facing change)
  • Internal .md docs updated (internal knowledge and AI code tools knowledge)
  • I have reviewed AI generated content

Summary by cubic

Fixes a 500 error when removing a generic attribute and its uniqueness constraint in the same schema update. We now drop constraint paths that reference attributes marked absent, so the update succeeds in one pass (addresses IFC-1238).

  • Bug Fixes
    • In process_attributes_state(), filter out uniqueness_constraints that reference attributes with state absent to avoid stale paths and AttributePathParsingError.
    • Expanded integration test TestGenericRemoveAttributesAndConstraints to assert rejection when only the attribute is removed and success when attributes and constraints are removed together.
    • Added changelog entry.

Written for commit 308f39d. Summary will update on new commits. Review in cubic

@solababs solababs requested a review from a team as a code owner May 19, 2026 11:54
@github-actions github-actions Bot added the group/backend Issue related to the backend (API Server, Git Agent) label May 19, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Shadow auto-approve: would auto-approve. This change adds a targeted filter to remove uniqueness constraint paths that reference attributes being deleted, preventing a 500 error during generic schema updates, and includes a thorough integration test to confirm the fix.

Re-trigger cubic

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 19, 2026

Merging this PR will not alter performance

✅ 12 untouched benchmarks


Comparing fix-generic-uniqueness-ifc-1238 (308f39d) with stable (72c3033)

Open in CodSpeed

Copy link
Copy Markdown
Contributor

@ajtmccarty ajtmccarty left a comment

Choose a reason for hiding this comment

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

can you update the description to explain why this works for a Node schema but does not for a Generic schema? I don't really understand why one works but not the other

async def test_final_validate(self, db: InfrahubDatabase) -> None:
await verify_no_duplicate_relationships(db=db)
await verify_no_edges_added_after_node_delete(db=db)
await assert_no_virtual_schema_relationships_in_db(db=db)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

accidental delete?

paths
for paths in updated_node.uniqueness_constraints
if not any(path.split("__", maxsplit=1)[0] in deleted_names for path in paths)
] or None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not certain this is what we want. for example, if I have uniqueness_constraints like this [["name__value", "color__value"], ["model__value", "color__value"]] and I remove color from the schema, then this logic would remove all the uniqueness constraints. at least, that's what it looks like to me, correct me if I'm wrong.

I think we need the user to decide what should happen to multi-element uniqueness constraints that include an attribute being deleted, so raising an error is probably the correct thing to do. Although I think it should be a ValueError and not a 500 Server Error

@solababs solababs requested a review from ajtmccarty May 25, 2026 09:24
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

0 issues found across 2 files (changes from recent commits).

Shadow auto-approve: would auto-approve. The one-line change in schema_branch.py filters out uniqueness constraint paths referencing attributes marked as absent, preventing the 500 error while keeping the logic narrow and safe, and the new integration tests thoroughly validate both the rejection of partial removal and success of...

Re-trigger cubic

Copy link
Copy Markdown
Contributor

@ajtmccarty ajtmccarty left a comment

Choose a reason for hiding this comment

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

it looks like this PR just adds a blank line and a test

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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Unable to update uniqueness_constraints on generic when removing attributes - Error 500

2 participants