Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 #261: Handle unique constraint validation error #777
base: master
Are you sure you want to change the base?
Fix issue #261: Handle unique constraint validation error #777
Changes from all commits
3a02a01
5ab41ad
944ad4c
ebd5ade
924d435
d1426d1
e207669
9133314
dde5952
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 cleaned it up a bit, and fixed type errors.
And now we can discuss what's happening here.
This branch is where new code added, and it looks like we're adding "original fields" again ... after they were removed? Maybe it's better to look for a place where they were removed?
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.
Also, what surprised me here is that we have added back original fields, but none of the tests failed.
I have added
test_model_with_constraint_fields
in master, and synced it here. But it still detects onlytitle, sub_title_de, sub_title_en
fields. This is good, because form looks like before, and bad, because I do not understand why :)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.
Thanks for cleaning the code.
While debugging I noticed the
_get_fieldsets_post_form_or_formset
is where the translation fields get added (I could be wrong). Does it make sense to move the logic to add original fields here?I am not entirely sure how this change fixed the issue. I made the changes purely based on my observation on how the code is executed.
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.
Oh, I see there's
replace_orig_field
, and it looks like it replaces original fields with translation ones.We can add option
preserve_original_fields
with default valueFalse
here. And now, instead of adding fields back - we just preserve it here.I'm not sure if we need
preserve_original_fields=False
at all, maybe just make preserving originals default behaviour. Check how it works.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.
Good idea. I will test it.
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.
This is basically the same as removed 243-244 lines. Right?
But, something feels not right here. If we have "fields" specified we're making changes to a code path, but when no fields specified - we're doing all like before?
(I may be wrong here, and maybe we're always have "fields" specified? But looking at the code coverage, this branch is also covered/executed, so it worth investigating)
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.
While debugging I noticed the
_get_form_or_formset
is called twice, one with fields and one without fields (attached screenshot). If I remove the else block then the translation fields are displayed twice. So, I had to retain the existing logic in theelse
block.