Order of module installation prevents proper access_policy field creation

Created on 30 November 2023, 12 months ago
Updated 7 December 2023, 12 months ago

Problem/Motivation

There is an issue appeared when I tried to install Menu Item Extras module β†’ on a site that already used access policy module as below:

In ExceptionHandler.php line 46:
                                                                                                                                                                                                                                                               
  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'drupal10.menu_link_content__access_policy' doesn't exist: SELECT "t".*                                                                                                                            
  FROM                                                                                                                                                                                                                                                         
  "menu_link_content__access_policy" "t"                                                                                                                                                                                                                       
  WHERE ("entity_id" IN (:db_condition_placeholder_0, :db_condition_placeholder_1, :db_condition_placeholder_2, :db_condition_placeholder_3, :db_condition_placeholder_4, :db_condition_placeholder_5, :db_condition_placeholder_6, :db_condition_placeholder  
  _7)) AND ("deleted" = :db_condition_placeholder_8) AND ("langcode" IN (:db_condition_placeholder_9, :db_condition_placeholder_10, :db_condition_placeholder_11))                                                                                             
  ORDER BY "delta" ASC; Array                                                                                                                                                                                                                                  
  (                                                                                                                                                                                                                                                            
      [:db_condition_placeholder_0] => 5                                                                                                                                                                                                                       
      [:db_condition_placeholder_1] => 6                                                                                                                                                                                                                       
      [:db_condition_placeholder_2] => 7                                                                                                                                                                                                                       
      [:db_condition_placeholder_3] => 8                                                                                                                                                                                                                       
      [:db_condition_placeholder_4] => 9                                                                                                                                                                                                                       
      [:db_condition_placeholder_5] => 11                                                                                                                                                                                                                      
      [:db_condition_placeholder_6] => 12                                                                                                                                                                                                                      
      [:db_condition_placeholder_7] => 13                                                                                                                                                                                                                      
      [:db_condition_placeholder_8] => 0                                                                                                                                                                                                                       
      [:db_condition_placeholder_9] => en                                                                                                                                                                                                                      
      [:db_condition_placeholder_10] => und                                                                                                                                                                                                                    
      [:db_condition_placeholder_11] => zxx                                                                                                                                                                                                                    
  )                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                               

In StatementWrapperIterator.php line 110:
                                                                                                                       
  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'drupal10.menu_link_content__access_policy' doesn't exist

I'm not sure if this issue is related to access policy module or menu item extras module, but I solved the issue when I uninstall access policy module then install the menu item extras module first, so I think there is something trying to alter some tables or entities before the installation of menu item extras finish.

Steps to reproduce

1- Install access policy module.
2- Install menu item extras module.
3- The above error will appear.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡―πŸ‡΄Jordan Odai Atieh Amman

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

Merge Requests

Comments & Activities

  • Issue created by @Odai Atieh
  • πŸ‡―πŸ‡΄Jordan Odai Atieh Amman
  • πŸ‡ΊπŸ‡ΈUnited States partdigital

    Hi Odai, thanks for reporting this!

    I was able to reproduce the issue. It indeed depends on the order in which the modules are enabled. If you enable the access_policy module first, the menu_content_item entity won't be updated to support the access_policy field. (menu_content_item__access_policy).

    What is odd is that for other modules it works as expected. For example, I can install the paragraphs module in any order and the access policy field gets added with no problem. This is probably happening because menu_item_extras is modifying an existing entity rather than creating a new one.

    My guess is that this is caused by a few factors coming together.

    1. By default, Drupal core content menu items do not support Access Policy.
    2. If access policy is enabled before menu_item_extras it sees that Access policy is not supported and doesn't add the field. If you then enable menu_item_extras it won't try to re-add the field. (which makes sense)
    3. When menu_item_extras is enabled before it adds bundles which opens Access policy support.
    4. If access policy is enabled after menu_item_extras it sees that Access is supported and it adds the field.

    You found a good one!

    A quick fix I can add is to simply exclude content menu items from Access policy entirely, unless of course you need to support Content menu items. Then I'll need to find another approach.

  • Status changed to Needs review 12 months ago
  • πŸ‡ΊπŸ‡ΈUnited States partdigital

    I've opened an MR for this issue. https://git.drupalcode.org/project/access_policy/-/merge_requests/6

    I've added an `installAccessPolicyField` method to the access policy create form that will only execute if the field does not exist. This is essentially a backup feature for rare cases (such as this) where the access policy field isn't properly installed.

    Give it a try and let me know if you encounter any other issues. Thanks again for finding this!

  • πŸ‡ΊπŸ‡ΈUnited States partdigital

    I've updated the MR so that it will attempt to install the field on access policy insert (if it doesn't exist). This addresses an issue with the previous approach where it may not be properly installed during configuration import.

  • Status changed to RTBC 12 months ago
  • πŸ‡ΊπŸ‡ΈUnited States partdigital
  • Status changed to Fixed 12 months ago
  • πŸ‡ΊπŸ‡ΈUnited States partdigital
  • πŸ‡ΊπŸ‡ΈUnited States partdigital
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024