Uploaded image for project: 'MusicBrainz Server'
  1. MusicBrainz Server
  2. MBS-11233

Seeding capability was broken during lodash removal

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2021-01-11
    • Component/s: Relationship editor
    • Labels:
      None

      Description

      In my "seed Concert event from an existing recording" userscript I use the capability to prefill fields in an Event creation page by using an URL like

      https://mb.o/event/create?edit-event.name=...
      &rels.0.target=...
      &rels.0.type=...
      &rels.1.target=...
      &rels.1.type=...

      This was working earlier this year, and I just checked on tag v-2020-08-24 it works as expected.

      It doesn't work on recent versions of MBS with a "Uncaught TypeError: i.attributes is undefined" in the javascript console of my browser.

       

      This capability was broken in MBS commit 1adc89f5c37 as far as I can tell, when lodash.transform(myArray, myFct...) was changed to myArray.reduce(myFct...). lodash.transform() accepted an 'undefined' myArray input (considered as equal to an empty array) and of course myArray.reduce() does not, which explains the error coming from root/static/scripts/relationship-editor/common/viewModel.js line~350 where rel.attributes is undefined:

       

      diff --git a/root/static/scripts/relationship-editor/common/viewModel.js b/root/static/scripts/relationship-editor/common/viewModel.js
      index 9a1ad9bd71..9247362813 100644
      --- a/root/static/scripts/relationship-editor/common/viewModel.js
      +++ b/root/static/scripts/relationship-editor/common/viewModel.js

      @@ -346,7 +347,8 @@ function addRelationshipsFromQueryString(source) {
      {{ };}}

      {{ if (linkType) {}}
      - data.attributes = rel.attributes.reduce(function (accum, attr) {
      + data.attributes = (rel.attributes ?? []).reduce(function (accum, attr) {
      {{ var attrInfo = linkedEntities.link_attribute_type[attr.type];}}

      {{ if (attrInfo && linkType.attributes[attrInfo.id]) {}}

       
      With the patch above my userscript restart working. There's still another bug left (when I have relations to different entity types, the wrong relation names are displayed) I want to take a look at, but I think at least this fix should be applied

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              reosarevok Nicolás Tamargo
              Reporter:
              loujin loujin
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Packages

                  Version Package
                  2021-01-11