Problem/Motivation

In case of per user managed flag_lists, mutliple flags with the same id may (will) be created, which breaks the admi/structure/flag page

NOTICE: PHP message: [error] [php] [192.168.64.1] [uid:1] [http://dev.materio.com/fr/admin/structure/flags] [http://dev.materio.com/fr/admin/structure/flag_lists/flag_list_item] Symfony\Component\Routing\Exception\InvalidParameterException: Parameter "flagging_collection" for route "entity.flagging_collection.canonical" must match "\d+" ("177|197|213" given) to generate a corresponding URL. in Drupal\Core\Routing\UrlGenerator->doGenerate() (line 204 of /var/www/html/d8.materio.com/public_html/web/core/lib/Drupal/Core/Routing/UrlGenerator.php).

Proposed resolution

on flag_lists flagging_collection creation, make the related_flag id unique.

Comments

bachbach created an issue. See original summary.

bachbach’s picture

Issue summary: View changes
bachbach’s picture

Status: Active » Needs review
StatusFileSize
new11.37 KB

i managed to set a uniq id based on flag_collection's id for the related_flag by moving all the flag creation stuff in hook_ENTITY_TYPE_insert() in flag_lists.module

here is a patch

WARNING: this patch includes the hasactions patch https://www.drupal.org/project/flag_lists/issues/3200585

[edit] i discovered that this is tha way flag.module is creating actions https://git.drupalcode.org/project/flag/-/blob/8.x-4.x/flag.module#L594

sl27257’s picture

Given the way the flag module is doing it, will your patch solve the problem? The reason for doing it the way it was done was to be compatible with the flag module. Maybe in the flag case the flags are managed from one place only and because of that it will not be able to create flags with the same name?

What did you do to create the original error? Is that because different user has the same name of the flag_lists?

bachbach’s picture

What did you do to create the original error? Is that because different user has the same name of the flag_lists?

yes exactly

Given the way the flag module is doing it, will your patch solve the problem?

yes Flag don't care about flag names, we can do what we want

The reason for doing it the way it was done was to be compatible with the flag module.

what could be incompatible ? as i said, flag don't care much about flag names

Maybe in the flag case the flags are managed from one place only and because of that it will not be able to create flags with the same name?

maybe

sl27257’s picture

Status: Needs review » Needs work

The unique part of this patch will later go into #3202208: Move Flag Lists actions into a submodule . The "has action part" might not be necessary.

sl27257’s picture

Assigned: Unassigned » sl27257
bachbach’s picture

i can provide a patch with only the uniq part

sl27257’s picture

Yes, please!

bachbach’s picture

StatusFileSize
new6.58 KB

here is the patch only for uniq_id

sl27257’s picture

Thanks!

sl27257’s picture

This is a slightly different patch. To my understanding it do the same. It doesn't however use hooks for the modules own entities.

There are still some things for me to verify. They are mostly related to importing from an old D7 site.

sl27257’s picture

StatusFileSize
new1.49 KB

Hmm, there were two active dpm() calls in the previous patch...

sl27257’s picture

Status: Needs work » Needs review

I have been running with this patch for some time now and I see no problems for my use cases.

  • sl27257 committed 2bbb041 on 4.0.x
    Issue #3200737 by sl27257, bachbach: make the related_flag id unique
    
sl27257’s picture

The pushed patch to the -dev also include an enhancement so that it is possible to identify the creator of each flag_list in the overview.

sl27257’s picture

Status: Needs review » Reviewed & tested by the community
bachbach’s picture

Status: Reviewed & tested by the community » Needs work

hi,

i have issues with this option for ids

[error]  Drupal\Core\Config\Entity\Exception\ConfigEntityIdLengthException: Attempt to create a bundle with an ID longer than 32 characters: inclusion_textile_metallique_17874(). in Drupal\Core\Entity\EntityBase->preSave() (line 439 of /var/www/html/d8.materio.com/public_html/web/core/lib/Drupal/Core/Entity/EntityBase.php). 
 [error]  Attempt to create a bundle with an ID longer than 32 characters: inclusion_textile_metallique_17874(). (/var/www/html/d8.materio.com/public_html/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php:846) 

with the label based ids, we can't be sure that the id will be less than 32 chars

what was the problem with the 'flagcol_' . $entity->id()
user will never care about the internal id

sl27257’s picture

Hi, sorry for not getting back to you earlier but I have been on vacation!

The main reason for not going directly for your solution was that it was not implemented inside the Class. When I looked into moving it into the Class there was no obvious way of getting the id of a entity to be created before it was actually created. It was a sort of "Catch 22" situation if I remember correctly. But of course it should be possible without indirectly affecting the useful length of the name (Like truncating the name of the Flaglist to be created).

Give me some time, (Being back from vacation means that my backlog currently is quite long...) and I will try to solve it and also fix an update function to update existing records.

/Thomas

sl27257’s picture

StatusFileSize
new2.05 KB

An attempt. But I need to review it a little more.

sl27257’s picture

StatusFileSize
new4.21 KB

Now also with an update function to update all old records to the new naming scheme.

  • sl27257 committed 937cec8 on 4.0.x
    Issue #3200737 by sl27257, bachbach: make the related_flag id unique
    
sl27257’s picture

Status: Needs work » Needs review
tlwatson’s picture

I am getting this error from the update in your new patch:
Call to a member function id() on null in flag_lists_update_8004()

Following this comment in another issue (and using DISTINCT in the first query, otherwise the first query is larger than the second), there are 2 names of relatedflag in flagging_collection_field_data that do not exist in config. I checked a copy of the DB from before trying to run this, and there was no discrepancy there before.

In other words, after trying and failing to run the update, this turns 67 rows (2 if I use 'SELECT DISTINCT relatedflag'):

SELECT *
FROM flagging_collection_field_data
WHERE relatedflag NOT IN (
    SELECT fd.relatedflag
    FROM flagging_collection_field_data fd
        INNER JOIN config c
        ON c.name LIKE CONCAT('flag.flag.', fd.relatedflag)
);

I will have to stick to RC1 for now.

tlwatson’s picture

Status: Needs review » Needs work
sl27257’s picture

Hi,

thank you for the report! Let me look into it!

/Thomas

sl27257’s picture

Hi,

I can't reproduce it here but what you basically is proposing is to add "DISTINCT" into all the 5 update questions in flag_lists_update_8004?

/Thomas

sl27257’s picture

StatusFileSize
new1.61 KB

Is this what you propose? I have not been able to test if it is OK.

I have also moved the update to a new update run. I am not sure if this is necessary. If you have skipped -rc2 then it should not be necessary because then 8004 has not been executed yet. But I can't fully figure out what happens if you have run -rc2. In my case it worked with -rc2. The upgrade contains a check to see if the name already is updated, so there should be no problem to run it again...

sl27257’s picture

Status: Needs work » Postponed (maintainer needs more info)

Unfortunately there is no such thing as distinct for updates. So this must be related to something else. To places where things has been shown to cause problems are the following:

#3257955: Error: Call to a member function isSyncing() on null in flag_lists_actions_flagging_collection_presave() (line 71 of modules/contrib/flag_lists/modules/flag_lists_actions/flag_lists_actions.module).
#3259130: Views support

Marks this as need more info

sl27257’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new3.47 KB

This patch doesn't fix the problem in #24 but it mitigates it so that it can be fixed later.

  • sl27257 committed b1824b8 on 4.0.x
    Issue #3200737 by sl27257, bachbach, TLWatson: make the related_flag id...
  • sl27257 committed cec6860 on 4.0.x
    Issue #3200737 by sl27257, bachbach, TLWatson: make the related_flag id...
sl27257’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.