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

Remove weirdness from Fingerprint methods #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Benestar
Copy link
Contributor

Methods to add, set or remove terms and multiterms from a Fingerprint do
not require a language code to be passed together with the term because
the language can be derived from the term object. In the current state
there can be inconsistencies in the datamodel allowing a wrong language
code to be set for a term in another language.

Note: Tests need to be updated. This is a breaking change!

Bug: T121433

@Benestar
Copy link
Contributor Author

o_O How can the tests actually pass after this breaking change? There must be something really wrong with the tests if they don't catch this up...

@thiemowmde
Copy link
Contributor

I do support the change. But as you said this needs more work and investigation. Especially: Where are these methods used?

@JeroenDeDauw
Copy link
Contributor

Wondering about usage as well. We do not have a hasLabel that takes a Term or a combination of language and text on the PHP side. Only hasFoo methods that take a language code.

* @param {wikibase.datamodel.Term} label
* @return {boolean}
*/
hasLabel: function( languageCode, label ) {
return this._labels.hasItem( languageCode, label );
hasLabel: function( label ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As @JeroenDeDauw said this should be hasLabel: function( languageCode ).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that we already have hasLabelFor below which does exactly that. We could just remove this method but I think it is useful if you don't only want to check if a label is set but also compare it to the value passed here.

@JeroenDeDauw
Copy link
Contributor

Ping @adrianheine @snaterlicious

@thiemowmde thiemowmde added this to the 2.0.0 milestone Dec 19, 2015
@thiemowmde thiemowmde modified the milestone: 2.0.0 Jan 13, 2016
@thiemowmde
Copy link
Contributor

This patch removes the first languageCode parameter from these functions:

  • Fingerprint.hasLabel (not used outside of Fingerprint.tests)
  • Fingerprint.setLabel (unused outside of tests)
  • Fingerprint.removeLabel (unused)
  • Fingerprint.hasDescription (unused)
  • Fingerprint.setDescription (unused)
  • Fingerprint.removeDescription (unused)
  • Fingerprint.hasAliases (unused)
  • Fingerprint.setAliases (used a single time in AliasesChanger)
  • Fingerprint.removeAliases (unused)

The inconsistent code in AliasesChanger vs. DescriptionsChanger vs. LabelsChanger is really, really weird:

  • Aliases changer edits the actual entity object. The other two changers do not. Huh?
  • Label and description changer do deferred.resolve( savedLabel ) with the changed label and description. Aliases changer doesn't do that. It does deferred.resolve() instead.

We talked about this and we think it's better to make the JavaScript DataModel immutable, mostly to get rid of unused code and complexity. Most (but not all) of this patch will be obsolete then.

@thiemowmde
Copy link
Contributor

I rebased this after #43/#59, updated the tests and did a little bit of a revert: I kept the error thrown in setAliases.

This "weirdness" was introduced in 73047ba, which was part of #16. I can not tell what the intention was. Possibly something with language fallbacks, where a Term object can have a language different from what the array key says.

I would like to have this in the 3.0 release.

@Benestar
Copy link
Contributor Author

Will rebase and fix the issues

@thiemowmde
Copy link
Contributor

It's rebased already. Sorry. I did not know you are working on this right now.

@adrianheine
Copy link
Contributor

How does this interact with fallback terms?

@thiemowmde
Copy link
Contributor

Good question. At the moment it does not "interact" at all, because these methods are all completely unused (1 exception, see above). In my opinion the design of these methods is bad and should be streamlined as this patch proposes. There is no need to "support" fallbacks at this level.

Almost all users of these functions will use them like this:

fingerprint.setLabel( label.getLanguageCode(), label );

It's completely pointless to even have the additional parameter then. It does not help protecting us from anything.

A proper solution would be an actual "fallback term" class that can not be used in setLabel and such.

@adrianheine
Copy link
Contributor

Ok, I would suggest to remove everything that's weird and unused, then, but I'm ok with merging it as it is, too.

@thiemowmde
Copy link
Contributor

I suggest to remove all this too, see #54. Should we start doing this in the planed 3.0 release?

@Benestar
Copy link
Contributor Author

Yes, if we already start cleaning up and want to do a breaking release, lets do this as a whole.

@thiemowmde
Copy link
Contributor

Since this patch also touches methods we do not want to remove, I suggest to merge this before #54.

@thiemowmde thiemowmde removed this from the 3.0.0 milestone Aug 2, 2016
Methods to add, set or remove terms and multiterms from a Fingerprint do
not require a language code to be passed together with the term because
the language can be derived from the term object. In the current state
there can be inconsistencies in the datamodel allowing a wrong language
code to be set for a term in another language.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

4 participants