MenuLinkContent menu_name max length is too long

Created on 13 October 2019, over 4 years ago
Updated 23 February 2024, 4 months ago

Problem/Motivation

MenuLinkContent::baseFieldDefinitions does not define a max_length which gets set to 255 but MenuTreeStorage::schemaDefinition only allows for 32 characters. When running createWithSampleValues this blows up.

Proposed resolution

  1. In MenuLinkContent baseFieldDefinitions(), add ->setSetting('max_length', \Drupal::state()->get('menu_link_content_menu_name_max_length', 32))
  2. In an update hook refresh the schema from the new field definition
  3. Also in the update hook retrieve menu name (MenuTreeStorageInterface::getMenuNames) and if there is anything over 32, record this in the state key
  4. Determine how and when to trigger a deprecation error

Remaining tasks

Update patch
Upgrade path?
Change record?

User interface changes

API changes

Is there a BC problem here? If someone used a different menu tree storage service then, in theory, they can have longer than 32 menu names.

Data model changes

Release notes snippet

๐Ÿ› Bug report
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Menu systemย  โ†’

Last updated 4 days ago

Created by

๐Ÿ‡จ๐Ÿ‡ฆCanada Charlie ChX Negyesi ๐ŸCanada

Live updates comments and jobs are added and updated live.
  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom jonathan1055

    New MR for 10.1.x - just one commit, the patch in #13 by YurkinPark. The tests failed before so will fail again.

  • @jonathan1055 opened merge request.
  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Since the MR has so many failures this still needs some works

    Also think there should be a test case and possibly an upgrade path

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom jonathan1055

    ... possibly an upgrade path

    Yes that is the single thing that is causing the test failures. They all have

    Custom menu link: The Menu name field needs to be updated.
    

    which is the outcome of running UpdatePathTestTrait runUpdates(), which is called from many tests. I think is due to there being no hook_update to set the loaded field definition to match the updated definition in code. When viewing the status page we get the usual

    The following changes were detected in the entity type and field definitions.
    Custom menu link - The Menu name field needs to be updated.
    


    I have been trying to write a hook_update to fix this but have not got it right yet. I can detect the problem but saving the field definition does not seem to make any effect. I could share what I've got so far.

  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom jonathan1055

    I've added the hook_update, took a while to discover how to get the schema updated. But this works locally in update.php and also in phpunit tests.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom jonathan1055

    Existing tests all pass now. Reading the issue summary, the hook update needs to set a state value if any existing menu_name is longer than 32. But it appears that this is an edge-case from reading comment #6

    The only ones affected are those who made a custom tree storage backend to allow for longer than 32 characters but have not yet used this capability

    I will add that, and it will inform how we write a test for this (if one really is needed)

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Looks good @jonathan1055!

    Moving to NW for the tests

  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom jonathan1055

    There are two questions here. , regarding a test for this, what do we actually want to test?

    1. Some tests check that a hook_update does what it is meant to do, but those are often when actual storage or entities are modified. All we are doing in this update is re-aligning the schema with the field definition.
    2. Or do we want to test that a menu cannot be added with a name longer than 32? Menu names already cannot be added with length longer than 32 via core UI. As mentioned in #6 the only way this could have been done is by writing a custom tree storage backend to allow for longer than 32 characters. I don't see how that could be feasable to be tested.
    3. Or do we want to check createWithSampleValues() no longer fails? For that we have the issue #3087634: Adds tests of createWithSampleValues โ†’ which is already set up to cover all fields, not just menu_name

    , in the update hook, the maximum length of existing menus can be found, but what exactly should be done with the answer? The original issue summary said 'store a state value' and 'create an exception in D10' but is that really the best thing? Could the hook_update either fail or give a warning instead? From what I understand, this change is aligning the field definition max length with what was already set to 32 in the menu storage definition. Any existing menu longer than 32 can still remain and will function fine without any need to be changed.

    Happy to continue on this, but I need some discussion and help with the above two questions. I came to fix this issue because I want to help the Devel users who have this problem, see #3027826: String data, right truncated: 1406 Data too long for column 'menu_name' โ†’ and the update on drupalspoons/devel issue 212

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    @jonathan1055

    I think we will want option 1 for sure.

    If 2 can't be achieved via core we may not need to test.

    3 can be covered in the other ticket I think.

    For your second question will have to defer to someone else.

  • Status changed to Needs work over 1 year ago
  • The Needs Review Queue Bot โ†’ tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide โ†’ to find step-by-step guides for working with issues.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States jrockowitz Brooklyn, NY

    Here is a patch that can be used via composer.json.

  • last update about 1 year ago
    29,380 pass
  • last update about 1 year ago
    29,383 pass
  • Status changed to Needs review about 1 year ago
  • Open on Drupal.org โ†’
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    Waiting for branch to pass
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia mohit_aghera Rajkot

    From the discussion on #27 and #28, I've implemented following changes.

    1. Added a test case to ensure that update hook is checking and updating state variables
    2. Added another test case with a scenario which covers a custom module that overrides the length of the menu name.
    Our service decorator is implementing core service and increasing a menu_name length. I've implemented this scenario as well.

    3. I think we might not need to test this as part of this ticket. Happy to explore ways if someone has other opinions.

    Patch is significantly larger than the one in #30 because of new test module.

    Do we need a CR for this one? Since it is just a minor change in the length of the menu name.

    I don't see a BC problem with custom modules overriding length as it has been covered in my test case patch.

  • 19:19
    19:01
    Running
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia mohit_aghera Rajkot

    Fixing code formatting issues and changing update hook number.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Removing the Needs tests tag as they appear to be added.

    Tried running the update hook on 11.x though and got

    >  [error]  TypeError: ArrayObject::__construct(): Argument #1 ($array) must be of type array, bool given in ArrayObject->__construct() (line 15 of /var/www/html/vendor/consolidation/output-formatters/src/StructuredData/AbstractListData.php) #0 /var/www/html/vendor/consolidation/output-formatters/src/StructuredData/AbstractListData.php(15): ArrayObject->__construct(false)
    > #1 /var/www/html/vendor/consolidation/output-formatters/src/StructuredData/UnstructuredListData.php(21): Consolidation\OutputFormatters\StructuredData\AbstractListData->__construct(false)
    > #2 /var/www/html/vendor/drush/drush/src/Commands/core/UpdateDBCommands.php(132): Consolidation\OutputFormatters\StructuredData\UnstructuredListData->__construct(false)
    

    May be unrelated but I can't update to give a review.

    Will leave in review if anyone else is able.

  • Status changed to RTBC about 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Okay I had to upgrade to drush12 to run but I was able to run.

    I'm 99% sure the issue is related to drush and not this patch.

    So the update hook ran fine and the changes seem simple enough.

    Not sure if a change record will be needed but will let committer decide.

  • last update about 1 year ago
    29,407 pass
  • last update about 1 year ago
    29,407 pass
  • 8:13
    4:08
    Running
  • last update about 1 year ago
    29,422 pass
  • last update about 1 year ago
    29,441 pass
  • last update about 1 year ago
    29,442 pass
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States Darren Oh Lakeland, Florida
  • last update about 1 year ago
    29,442 pass
  • last update about 1 year ago
    29,450 pass
  • last update about 1 year ago
    29,429 pass
  • last update about 1 year ago
    30,283 pass, 33 fail
  • @darren-oh opened merge request.
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    @darrenoh what are you changing this was previously RTBC but will have to go through review again.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States Darren Oh Lakeland, Florida

    There was a merge request for 9.3.x. No chance that would get accepted.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    #33 the last the last patch uploaded.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States Darren Oh Lakeland, Florida

    Hid the other patches. Leaving merge requests for those who need this fix for D9 and D10.

  • last update about 1 year ago
    29,430 pass
  • last update about 1 year ago
    30,283 pass, 33 fail
  • last update about 1 year ago
    30,339 pass, 2 fail
  • last update about 1 year ago
    30,339 pass, 2 fail
  • Open on Drupal.org โ†’
    Environment: PHP 8.2 & MySQL 8
    last update about 1 year ago
    Not currently mergeable.
  • @darren-oh opened merge request.
  • last update about 1 year ago
    28,526 pass
  • Status changed to Needs work about 1 year ago
  • The Needs Review Queue Bot โ†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide โ†’ to find step-by-step guides for working with issues.

  • Status changed to Needs review about 1 year ago
  • last update about 1 year ago
    29,510 pass
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia mohit_aghera Rajkot

    Looks like PR !4197 and !4181 seems to be missing the test cases added in #43
    Adding test cases again in the patch.

    Patch was not getting applied cleanly to 11.x. So re-rolled that.
    Re-roll diff is against #43 only.

  • Status changed to Needs work about 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Thanks @mohit_aghera!

    One of the proposed solution items is

    Determine how and when to trigger a deprecation error

    Is that still needed?

    Definitely think a change record will be needed

  • last update 11 months ago
    29,450 pass
  • last update 11 months ago
    28,526 pass
  • last update 11 months ago
    30,339 pass, 2 fail
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States j.cowher

    Re-rolling for 9.5.11. The system schema version gets updated to 1011 with the current patches which could mess things up when it comes time to upgrade to Drupal 10.

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Environment: PHP 8.1 & MySQL 5.7 updated deps
    last update 9 months ago
    30,340 pass, 2 fail
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium kristiaanvandeneynde Antwerp, Belgium

    What on earth is going on in that MR?

    The patch from #44 seems to be the the most recent that also applies to HEAD. Will give that one a go and report back.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States bstan

    Re-roll patch from #44 to be compatible with changes from issue #2869568

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States MegaKeegMan

    I am working on a site that uses layout builder, and the preview on the manage layout page runs createWithSampleValues which does result in the database error:
    String data, right truncated: 1406 Data too long for column 'menu_name'

    I applied patch 48 and the error went away. Drupal 10, PHP 8.1

Production build 0.69.0 2024