-
Notifications
You must be signed in to change notification settings - Fork 261
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
Extend update_fields with translation fields in Model.save() #687
Extend update_fields with translation fields in Model.save() #687
Conversation
@last-partizan Tests for django < 4.2 fail because we don't add the original field in Hence the following code updates only instance, created = models.TestModel.objects.update_or_create(
pk=obj.pk, defaults={'title_de': 'NEW DE TITLE 2'}
) Should we update the original field in the code below? |
Are you sure? Looking at But, for the sake of consistency, i think it's fine to update 'title' when passing |
Oh, hevermind, i read it other way. You're correct. |
The same errors (or behavior) were relevant for the removed implementation of |
The current django-modeltranslation version saves the last assigned value to the original field into "title" column even when a secondary language is active currently. Check the sample below >>> obj = TestModel(title='default')
... with override('en'):
... obj.title = 'English variant'
... obj.save()
...
... TestModel.objects \
... .rewrite(False) \
... .filter(pk=obj.pk) \
... .values('title', 'title_de', 'title_en') \
... .first()
{
"title": "English variant",
"title_de": "default",
"title_en": "English variant",
} So "title" might store not only the default translation (-- that looks strange to me). Should we check the currently active language to determine when the original field ( |
AFAIK, docs are suggesting "not rely on the original field anymore", becouse it can be incosistent. If we can make it consistent with minimal changes, then yes, let's do it. But if that would be too much rewriting, we should leave this for separate refactoring - if you want to fix it. Right now we should focus on solving "Extend update_fields with translation variants", without breaking update_or_create. Maybe we even should exclude "title" from assertions, to get tests to pass. |
I excluded "title" from the assertion. Not sure I can find the right approach now due to my limited knowledge of the codebase |
@andrei-shabanski please, add a note about this in the test. |
Please reabse it on latest master, CI was broken because latest mariadb was failing to start. |
44c502a
to
6fc1b08
Compare
a5ef7eb
to
511155b
Compare
An alternative approach to resolving #682
Override
QuerySet._update()
to update translation fields if only an original field is passed insave()
in argumentupdate_fields