Entity subqueues should be compatible with the core workspace module

Created on 11 September 2024, 2 months ago

Problem/Motivation

The workspace module assumes numeric ID for the entities for associating with a workspace in the workspace_association table. The IDs for the Drupal\entityqueue\Entity\EntitySubqueue are in string format.

Steps to reproduce

  • Install vanilla Drupal.
  • Enable workspace module.
  • Install and enable drupal/entityqueue module.
  • Create a new entityqueue with "Queue type" as "Multiple subqueues".
  • Create a new workspace and switch to it.
  • Open the newly created entity queue -> click on "view subqueues" and click "+ Add subqueue".
  • Fill in the values and try to save.

Expected result: You should be able to add the subqueue.

Actual result: The following exception is thrown

Drupal\Core\Entity\EntityStorageException: SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'test' for column `db`.`workspace_association`.`target_entity_id` at row 1: INSERT INTO "workspace_association" ("workspace", "target_entity_revision_id", "target_entity_type_id", "target_entity_id") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array ( [:db_insert_placeholder_0] => stage [:db_insert_placeholder_1] => 3 [:db_insert_placeholder_2] => entity_subqueue [:db_insert_placeholder_3] => test ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 817 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

Proposed resolution

If possible, adjust the ID for the subqueue entity type to be numeric.

Please note that this was also reported at #3221151: Entity Keys are not according to the Drupal Standards.

Remaining tasks

Check if this is feasible and required, and implement it.

User interface changes

None.

API changes

TBD

Data model changes

ID change from string to numeric.

🐛 Bug report
Status

Active

Version

1.0

Component
Workspaces 

Last updated about 3 hours ago

No maintainer
Created by

🇮🇳India ajits India

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @ajits
  • Status changed to Closed: won't fix 2 months ago
  • 🇷🇴Romania amateescu

    Workspaces need to be changed to work with entities that have string IDs, not the other way around :)

  • 🇮🇳India ajits India

    Thank you, @amateescu!
    Moving the core with IS update.

  • Status changed to Active 2 months ago
  • 🇮🇳India ajits India

    Correct component.

  • 🇮🇳India ajits India

    Adjusted title.

  • 🇳🇿New Zealand quietone

    Changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to our policies.

  • 🇷🇴Romania amateescu

    I've been thinking about this problem for the past few days and I think there's no other solution than adding a new target_entity_id_string column to the workspace_association table, and adjust all the code to use it as needed.

  • Pipeline finished with Failed
    about 2 months ago
    Total: 678s
    #289906
  • 🇺🇸United States smustgrave

    Assuming it was NR for thoughts on approach?

    But think adding a new column makes sense. Not as familiar with entityqueue but are they doing anything off that causes this?

    Agree with the tags being added.

  • 🇮🇹Italy plach Venezia

    Just for posterity reference: I asked @amateescu why we are not just converting the target_entity_id field type from int to string. The reason is that Postgres can't do joins on columns with different types.

  • Pipeline finished with Canceled
    about 2 months ago
    Total: 180s
    #292172
  • 🇮🇹Italy plach Venezia

    I pushed a commit to take removed entity types into account, as I got the following error when trying to run the latest wse updates:

    >  [notice] Update started: wse_menu_update_10002
    >  [error]  The "wse_menu_tree" entity type does not exist. 
    >  [error]  Update failed: wse_menu_update_10002 
    
  • Pipeline finished with Failed
    about 2 months ago
    Total: 631s
    #292174
  • Pipeline finished with Failed
    about 2 months ago
    Total: 159s
    #292300
  • Pipeline finished with Success
    about 2 months ago
    Total: 1175s
    #292498
  • 🇷🇴Romania amateescu

    Added test coverage for the problem we're fixing, but I'm not sure whether we're still doing upgrade path tests..

  • 🇺🇸United States smustgrave

    Since the update hook is adding a column and unique key think test coverage probably would be good idea though. Even if just simple

    does column and key exist = no
    run updates
    does column and key exist now = yes

  • Pipeline finished with Failed
    about 1 month ago
    Total: 390s
    #299742
  • Pipeline finished with Failed
    about 1 month ago
    Total: 105s
    #300631
  • 🇷🇴Romania amateescu

    While using this MR on a site, we noticed that tables without primary keys are discouraged since https://www.drupal.org/node/3264101 , so I changed the approach and provided default values for both target_entity_id and target_entity_id_string columns, and used them in the primary key of the workspace_association table.

    In practice, this means workspaces can't support entities with a 0 integer ID (e.g. users), but I don't really see any way around that, and users were not supported anyway.

    Also added upgrade path test coverage, this should be fully ready for reviews now.

  • Pipeline finished with Success
    about 1 month ago
    Total: 326s
    #300645
  • 🇮🇹Italy plach Venezia

    The solution to restore the primary key and default to 0 for the int ID makes sense to me: users are not supported and even if they were, the anonymous user wouldn't be editable. Any content entity out there with numeric ID relying on core base classes will start from 1, so I think this is a safe approach.

    The MR code has been working nicely in production for a while now, except for the latest update, and tests look good, so I think we are done here.

  • 🇬🇧United Kingdom catch

    Sorry I have one question:

    target_entity_id is currently 'not null' => TRUE, however if target_entity_id_string is set, then it can and should be unset.

    So... instead of adding a default value of 0, why not make target_entity_id 'not null' => FALSE?

    The primary key would still enforce that either target_entity_id or target_entity_id_string has a value, or at least that more than one row has a value, because two rows with the same null/empty values would be forbidden. So from that perspective it's just as strict as the current MR, since you could have one row with 0/'' in there as it is.

    Theoretically and for the same reason, target_entity_id_string could also allow null.

  • 🇷🇴Romania amateescu

    @catch, that's because we enforce all columns of a primary key to be 'not null' => TRUE since #2616724: Warn when trying to create a database table with a NOT NULL => FALSE primary key .

    The alternative would be to create a UNIQUE key instead, and that's what the MR did at first (essentially implementing your proposed schema definition for those columns), but the mysql db driver complains about tables with missing primary keys since 🐛 Use READ COMMITTED by default for MySQL transactions Fixed , see mysql_requirements().

  • 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 necessarily 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.

  • 🇷🇴Romania amateescu

    Rebased.

  • Pipeline finished with Failed
    27 days ago
    Total: 529s
    #313880
  • Status changed to Needs work about 17 hours 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 necessarily 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.

  • Pipeline finished with Canceled
    about 4 hours ago
    Total: 123s
    #338686
  • Pipeline finished with Success
    about 4 hours ago
    Total: 501s
    #338688
Production build 0.71.5 2024