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 labels to domains #6254

Merged
merged 2 commits into from
Feb 20, 2025
Merged

Add labels to domains #6254

merged 2 commits into from
Feb 20, 2025

Conversation

gerrod3
Copy link
Contributor

@gerrod3 gerrod3 commented Feb 3, 2025

fixes: #6236

Side note: I used Cursor & its agent feature to make this commit. With just some minor edits, it correctly added everything on its own. It even knew to run the migration command after adding the field (of course I had to manually run it since it didn't know about our oci-env). Maybe we should take a look at our issue backlog and note the simple/medium issues that we can throw to the AI (I'll take requests 😄).

Copy link
Member

Choose a reason for hiding this comment

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

Can you elaborate on changing this old migration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So as you can see the CI is failing on the migrations because I made the grave mistake of calling outside model code (get_domain_pk) from inside a migration (any migration adding a pulp_domain relation). On a new installation this causes the old migrations to fail now since I've added a new field to the Domain model which means the SQL the outside code generates will be too far ahead of the database at the time of the migration. So I had to change this migration and I'm going to have to change get_domain_pk to only pull in the pk.

Copy link
Member

Choose a reason for hiding this comment

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

So I see the add_domain_relations migration failing. I think we should fix that one instead.

@gerrod3 gerrod3 marked this pull request as ready for review February 17, 2025 22:40
@@ -58,4 +66,5 @@ class Migration(migrations.Migration):
bases=(django_lifecycle.mixins.LifecycleModelMixin, models.Model, pulpcore.app.models.access_policy.AutoAddObjPermsMixin),
),
migrations.RunSQL(DEFAULT_DELETE_TRIGGER, reverse_sql=REMOVE_DEFAULT_DELETE_TRIGGER),
migrations.RunPython(code=create_default_domain, reverse_code=migrations.RunPython.noop),
Copy link
Member

Choose a reason for hiding this comment

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

As a rule of thumb we established that runpython is good to migrate existing data to a new format. But for creating new data, you should really rely on the post-migrate hook.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not possible. We need the default domain for the next migration to work. Without this we can't start up a clean Pulp instance.

@@ -580,7 +580,8 @@ def get_default_domain():
except AttributeError:
return None
try:
default_domain = Domain.objects.get(name="default")
queryset = Domain.objects.only("pk") if pk_only else Domain.objects
default_domain = queryset.get(name="default")
Copy link
Member

Choose a reason for hiding this comment

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

This line will cache whatever we received as the domain. Even if it was only the shallow "pk only" version.
can we, instead leave this function alone and add a fallback implementation to get_domain_pk. With a big banner that it will be used in migrations...

@gerrod3 gerrod3 force-pushed the domain-labels branch 2 times, most recently from a8c46da to 40d3569 Compare February 18, 2025 18:13
Comment on lines 598 to 603
"""
THIS CAN/WILL BE RAN IN MIGRATIONS. DO NOT USE ORM FOR IT MIGHT GENERATE INVALID SQL.
"""
Copy link
Member

Choose a reason for hiding this comment

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

Thank you! This will help us not break it in the future.

Copy link
Member

Choose a reason for hiding this comment

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

Can you add that we use it in plugin migrations so there is no way to move this implementation and we must not change it's semantics ever.
Feels like BaseDistribution reloaded.

Copy link
Member

@mdellweg mdellweg left a comment

Choose a reason for hiding this comment

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

I am convinced that this is probably the best we can do.
So my ask is to fasten the guardrail comments a bit more.

Comment on lines 598 to 603
"""
THIS CAN/WILL BE RAN IN MIGRATIONS. DO NOT USE ORM FOR IT MIGHT GENERATE INVALID SQL.
"""
Copy link
Member

Choose a reason for hiding this comment

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

Can you add that we use it in plugin migrations so there is no way to move this implementation and we must not change it's semantics ever.
Feels like BaseDistribution reloaded.

@mdellweg mdellweg dismissed their stale review February 19, 2025 10:10

The situation around migrations including ones of dependent plugins does not allow to solve this "properly".
Thank you for the detailed explanation.

Also modify get_domain_pk to use raw SQL to avoid problems with running inside migrations
@mdellweg
Copy link
Member

Thank you!

@mdellweg mdellweg merged commit d51fd1a into pulp:main Feb 20, 2025
12 checks passed
@gerrod3 gerrod3 deleted the domain-labels branch February 20, 2025 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Labels for Domains
2 participants