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 for unintuitive merge logic when no fields are selected. #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

marcelchastain
Copy link

By default, the merge feature assumed the user wanted to merge all
fields when no fields were provided. This was inconsistent with the
merge preview display, and surprising to the user.

Finally ``other`` will be deleted and master will be preserved

@param master: Model instance
@param other: Model instance
@param fields: list of fieldnames to merge
@param commit: bool

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like the order of parameter types should match the order in the parameter list of the function?

@param m2m: list of m2m fields to merge. If empty will be removed
@param related: list of related fieldnames to merge. If empty will be removed
@return:
"""

fields = fields or [f.name for f in master._meta.fields]
# Ensure we have a valid iterable.
fields = fields if fields else []

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why stray from fields or []?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got some feedback from Andy on a previous PR about the "or" syntax; he mentioned preferring if/else.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like Django source code uses:

if fields is None:
   fields = []

I would drop # Ensure that we have a valid iterable. since there isn't an actual check whether we can iterate over fields.

@@ -73,7 +73,7 @@ class Media:
js = [
'admin/js/vendor/jquery/jquery.js',
'admin/js/jquery.init.js',
'adminactions/js/merge.min.js',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason to no longer use the minified version?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this with the minified vs the plain, and the minified had the original bug in it while the plain worked as expected.
Good call though, I'll put in a bit of effort to see if I can get the minified version working; no use having a phantom bug waiting for us down the line.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, yeah just pushed tried to minify it myself (UglifyJS 3) and the minified version doesn't work :(
Might be worth it to disable some minification options and try a few more times.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you min removing the minified version then? Somebody (most likely me) will come along shortly and try to switch to it.

@marcelchastain
Copy link
Author

marcelchastain commented Jun 15, 2018

@tvogels01 verified that minification breaks merge.js, so I think we can stick with the unminified version!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants