Skip to content

IFC-2458: Update profile and template on changing unique attribute#9194

Merged
solababs merged 12 commits into
stablefrom
sb-08052026-fix-update-attribute-does-not-affect-template-schema-ifc-2458
May 18, 2026
Merged

IFC-2458: Update profile and template on changing unique attribute#9194
solababs merged 12 commits into
stablefrom
sb-08052026-fix-update-attribute-does-not-affect-template-schema-ifc-2458

Conversation

@solababs

@solababs solababs commented May 8, 2026

Copy link
Copy Markdown
Contributor

Why

This PR ensures that removing unique: True from a schema attribute correctly triggers the AttributeSupportsGeneratedSchemaMigration, which adds the attribute to all existing profile and template node instances.

Closes #8894

How to test

uv run pytest backend/tests/component/core/migrations/schema/test_attribute_supports_generated_schema.py -v

Checklist

  • Tests added/updated
  • Changelog entry added (changelog/8894.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

@github-actions github-actions Bot added the group/backend Issue related to the backend (API Server, Git Agent) label May 8, 2026
@codspeed-hq

codspeed-hq Bot commented May 8, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 12 untouched benchmarks


Comparing sb-08052026-fix-update-attribute-does-not-affect-template-schema-ifc-2458 (0ce2d1b) with stable (2f720ae)1

Open in CodSpeed

Footnotes

  1. No successful run was found on stable (74d5b24) during the generation of this report, so 2f720ae was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@github-actions github-actions Bot added the type/documentation Improvements or additions to documentation label May 8, 2026
@solababs solababs marked this pull request as ready for review May 8, 2026 11:34
@solababs solababs requested review from a team as code owners May 8, 2026 11:34
Comment thread generated/infrahub/schema/develop.json Outdated

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.

what are these files?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

they were automatically generated, and the generated/ is not in .gitignore

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.

what are they? should they be included?

Comment on lines +476 to +485
# When a user removes unique=True from their schema definition, the uniqueness_constraints
# are rebuilt from scratch (not inherited). Replicate that by removing the stale entry.
# Constraint paths use the "attr__value" format (e.g. "nbr_seats__value"), so we must
# check startswith rather than an exact string match.
if new_car_schema.uniqueness_constraints:
new_car_schema.uniqueness_constraints = [
paths
for paths in new_car_schema.uniqueness_constraints
if not any(p == "nbr_seats" or p.startswith("nbr_seats__") for p 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.

can you just set new_car_schema.uniqueness_constraints to whatever it should be instead of doing it programatically? it seems like this should be a known value

) -> SchemaBranch:
"""TestDevice (generate_template=True) has COMPONENT TestPart (generate_template=False).
serial_number starts unique=True so it is NOT on template instances."""
part = _PART.model_copy(deep=True)

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 believe our duplicate() method would work here

return registry.schema.register_schema(schema=SchemaRoot(nodes=[_DEVICE, part]), branch=default_branch.name)


async def test_migration_unique_enable_support_sub_template(

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 think this case deserves to be in an integration test, either a new one or an existing one. it should ensure that the template schema and instance correctly have the expected attribute added/removed when the attribute's uniqueness is updated

@ajtmccarty ajtmccarty left a comment

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.

this looks good. I think it is ready to merge once those generated/ files are addressed

Comment thread changelog/8894.fixed.md Outdated
@@ -0,0 +1 @@
Changing `unique` to `False` on a schema attribute now correctly triggers a migration that adds the attribute to existing profile and template nodes.

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.

we try to say objects instead of nodes

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

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.

No issues found across 9 files

Confidence score: 5/5

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

Shadow auto-approve: would require human review. This PR modifies the schema migration trigger for the 'unique' attribute, which is a core business logic change affecting data integrity and migration behavior, so a human review is warranted to ensure correctness and completeness, especially since the test coverage only addresses one direction...

Re-trigger cubic

@solababs solababs merged commit 6f33de1 into stable May 18, 2026
56 checks passed
@solababs solababs deleted the sb-08052026-fix-update-attribute-does-not-affect-template-schema-ifc-2458 branch May 18, 2026 09:49
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/documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: updating attribute unique does not add/remove from Template schemas

2 participants