Closed dmos62 closed 1 year ago
My untested theory is that this has to do with validations. Some fields on UIQuery
declare validators and they are the fields mentioned in the generated migration. We use validator factories to create those validators, which might be messing up Django's introspection.
I'll note that it's unclear to me why migrations should care about field validators.
Here is a link for a SO post similar to this issue: https://stackoverflow.com/questions/55089705/django-keeps-creating-new-migrations-even-when-model-has-not-changed
Update with comments by me and Mukesh:
The problem is the validation functions for some of the fields of UIQuery
are being generated via a factory.
@silentninja adds:
The migrations bug is same as https://github.com/centerofci/mathesar/pull/2082. There is no way for Django to verify if it is the same function/
That implies that if we move the generation of validation functions out of the declaration, so that a given field will always have the same function referenced as its validator, that will fix endless migrations.
@dmos62
why are we using wraps
decoration in validators?
@aagman945 I don't recall the details, but I left a code comment next to their usages saying that it's needed to interop with Django's migrations.
A solution to this might be to instantiate each of the validator functions globally (top of the file) and then pass them to UIQuery fields (instead of instantiating them inside the field declarations). What's annoying about that is that you then redundantly hardcode field names outside their definition. Which is why I used factories (which apparently broke migration detection).
@dmos I tried instantiating validator globally it didn't worked.
We to use class based validator, and __eq__
method will take care of duplicate migrations. I tried this approach and it fixes our problem.
@aagman945 I wonder why that didn't work. Not sure what you mean about __eq__
. If you submit a PR and we can discuss implementation there.
@dmos62 I've created a PR with changes.
Multiple people reported that running
docker exec mathesar_service sh -c "python manage.py makemigrations"
always creates a new migration, even if you run it multiple times in sequence, that looks like this:Subsequent runs create migrations that have the previous migration as its dependency. That's the only difference between these redundant migrations.
The STDOUT is: