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

Fix issue with save on translation form #6037

Merged
merged 3 commits into from
Aug 7, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions readthedocs/projects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,12 +614,14 @@ def get_translation_queryset(self):
)
return queryset

def save(self):
project = self.parent.translations.add(self.translation)
# Run symlinking and other sync logic to make sure we are in a good
# state.
self.parent.save()
return project
def save(self, commit=True):
if commit:
self.translation.main_language_project = self.parent
self.translation.save()
Copy link
Member

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?

Copy link
Contributor Author

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.

# Run symlinking and other sync logic to make sure we are in a good
# state.
self.parent.save()
return self.parent


class TranslationForm(SettingsOverrideObject):
Expand Down