Skip to content

[FIX] Edit Domain: Prevent duplicate variable names#2146

Merged
lanzagar merged 2 commits intobiolab:masterfrom
jerneju:gh-2143-editdomain-duplicate
Apr 10, 2017
Merged

[FIX] Edit Domain: Prevent duplicate variable names#2146
lanzagar merged 2 commits intobiolab:masterfrom
jerneju:gh-2143-editdomain-duplicate

Conversation

@jerneju
Copy link
Contributor

@jerneju jerneju commented Mar 28, 2017

Issue

Edit Domain enables us to write duplicate names and that should be allowed. However user should be informed about that.
#2143

Description of changes

User is warned when writing a duplicate name. Also, empty spaces are removed in the beginning and in the end of a new name.

Includes
  • Code changes
  • Tests
  • Documentation

@jerneju jerneju changed the title [FIX] Edit Domain - writing duplicate names is prevented [FIX] Edit Domain: writing duplicate names is prevented Mar 28, 2017
@codecov-io
Copy link

codecov-io commented Mar 28, 2017

Codecov Report

Merging #2146 into master will increase coverage by 0.01%.
The diff coverage is 97.61%.

@@            Coverage Diff             @@
##           master    #2146      +/-   ##
==========================================
+ Coverage   72.13%   72.14%   +0.01%     
==========================================
  Files         318      318              
  Lines       54691    54717      +26     
==========================================
+ Hits        39450    39476      +26     
  Misses      15241    15241

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 22196a6...4190bd4. Read the comment docs.

Copy link
Contributor

@janezd janezd left a comment

Choose a reason for hiding this comment

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

  1. The widget should indicate that the name is duplicated instead of silently ignoring the change.

  2. The user can still assign the same new name to two attributes. I can rename all attributes to "foo".

self.main_form.addRow("Labels:", vlayout)

def set_data(self, var):
def set_data(self, var, var_names=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

Using var_names=() as default would simplify is_same, wouldn't it?

self.main_form.addRow("Values:", self.values_edit)

def set_data(self, var):
def set_data(self, var, var_names=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

Also here, you can probably replace None with ().

except Exception:
pass
current.set_data(None)
current.set_data(None, None)
Copy link
Contributor

Choose a reason for hiding this comment

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

And then () (or nothing) instead of the second None, too.

temp_var_names.remove(self.var.name)
else:
temp_var_names = []
return ((name in temp_var_names)
Copy link
Contributor

Choose a reason for hiding this comment

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

This function checks whether it is necessary to change the domain. You shouldn't abuse it to check whether it's legal to change the domain. (See the general comment.)

@jerneju jerneju changed the title [FIX] Edit Domain: writing duplicate names is prevented [FIX] Edit Domain: when duplicate is entered user is informed Apr 5, 2017

box.layout().addWidget(self.editor_stack)

self.Warning.add_message(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think two variables with the same name should produce an error and require a fix before proceeding (instead of displaying a warning and working on)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, @janezd has different opinion (see above).

Copy link
Contributor

Choose a reason for hiding this comment

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

I think @janezd didn't like that the change was ignored without a message. I don't see anything about whether the message should be a warning or an error.
We do not want to allow duplicate names (which is not just a cosmetic guideline, it can cause serious problems in the code, because we can index by names etc), so the widget should not output incorrect data. In that case an error is the only appropriate type of message.

self.domain_model[self.selected_index] = new_var


var_names = [vn.name for vn in self.domain_model]
Copy link
Contributor

Choose a reason for hiding this comment

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

This is now checked only on variable changes. If I see the warning and reset a variable to the original, the warning does not disappear (the reset functions don't reach this code).
Maybe the check could be moved to commit:

  • if everything is ok, remove the error and proceed
  • if not, show the error and send None

@lanzagar
Copy link
Contributor

lanzagar commented Apr 7, 2017

Also, editing a variable name and pressing enter does not work... Maybe that's a separate issue, but if it is easy to fix it can perhaps be added here?

@jerneju
Copy link
Contributor Author

jerneju commented Apr 7, 2017

@lanzagar: Yes, pressing enter is another issue.

jerneju added 2 commits April 7, 2017 16:34
White spaces in the beginning and in the end of the name are removed.
Empty names are not allowed.
GH-2143
@lanzagar lanzagar changed the title [FIX] Edit Domain: when duplicate is entered user is informed [FIX] Edit Domain: Prevent duplicate variable names Apr 10, 2017
@lanzagar lanzagar merged commit bf4ed5e into biolab:master Apr 10, 2017
@jerneju jerneju deleted the gh-2143-editdomain-duplicate branch April 21, 2017 14:26
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.

4 participants