-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Fix issue with save on translation form #6037
Conversation
The translation was not being saved before adding to the parent project. This surfaced an issue when the database is different, like in the case where we use a database router to send read/write operations to different databases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks correct to me.
I didn't test it locally with a DB router, though.
return project | ||
def save(self, commit=True): | ||
if commit: | ||
self.translation.save() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you like to add a comment explaining a little more why this is required here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made the fix clearer. The problem is that when calling add()
, self.parent
isn't the object that is updated. The field that is updated is self.translation.main_language_project = self.parent
. Calling save()
first was a method to make the object state use the database that matches db_for_write()
. Reversing this logic makes this less of a hack and skips usage of add()
altogether.
It's not entirely clear why this is an issue on only the translation relationship however.
Some things I found here. At this point This is the line where django makes it fail. Believe this is a django bug? I didn't find anything mentioning this case in the docs or in a google search |
When making |
updated my other PR to use Using |
Codecov Report
@@ Coverage Diff @@
## master #6037 +/- ##
==========================================
- Coverage 79.25% 79.24% -0.01%
==========================================
Files 175 175
Lines 11177 11179 +2
Branches 1395 1396 +1
==========================================
+ Hits 8858 8859 +1
Misses 1946 1946
- Partials 373 374 +1
Continue to review full report at Codecov.
|
I came across all of this in my debugging, which is why this PR originally called |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with this 👍. We should track the other issue in .com where we use the custom db router
The translation was not being saved before adding to the parent project.
This surfaced an issue when the database is different, like in the case
where we use a database router to send read/write operations to
different databases.