Warning: foreach() argument must be of type array|object, string given

Created on 24 December 2024, 3 months ago

Warning: foreach() argument must be of type array|object, string given in Drupal\anonymous_login\EventSubscriber\AnonymousLoginSubscriber->paths() (line 273 of modules/contrib/anonymous_login/src/EventSubscriber/AnonymousLoginSubscriber.php).

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇮🇱Israel heyyo Jerusalem

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

Merge Requests

Comments & Activities

  • Issue created by @heyyo
  • Merge request !14fix the issue → (Open) created by abhishek_virasat
  • 🇮🇳India abhishek_virasat

    @heyyo, I have fixed the issue and created MR, please review it once

  • Pipeline finished with Success
    3 months ago
    Total: 255s
    #378733
  • 🇮🇳India rohan_singh India

    Hi,
    Can you please help me with the steps to reproduce this issue?
    As per the configuration, the paths key is defined as a sequence, which should return an array.

    mapping:
        paths:
          type: sequence
          label: 'Anonymous login page paths.'
          sequence:
            type: string
            label: 'Path'

    Thanks!

  • 🇩🇪Germany berliner

    The problem seems to appear when updating from 1.x to 2.x, having existing configuration and using drush deploy (see https://www.drush.org/13.x/deploycommand/) as part of the deployment chain.
    In this case, what happens is this:

    1. The post update hook is run (as part of drush updatedb) and correctly changes the format of stored config paths in configuration to match the new type sequence
    2. Config import is run and overwrites the changes from the previous step with the stored configuration in the now outdated format

    So I guess, that the instead of a post_update hook, a deploy hook should be used.

  • 🇩🇪Germany berliner

    This patch moves the logic of updating the format of the configuration from a post deploy hook to a deploy hook.

  • 🇩🇪Germany berliner

    Adding a new patch that should also work if the the post_deploy hook had already run.

  • 🇨🇭Switzerland mullzk

    Thanks @berliner for your patch. I tested it with my installation on 10.4.1 and can confirm that it works with drush deploy.

    However - now only drush deploy works; updating with drush cr && drush updb && drush cr does not change the config and leads to the mentioned issues. Shouldn't both ways be supported?

  • 🇮🇹Italy uccio Turin

    I encountered this problem going back and forth between version 2.1 and 2.2.
    I believe the problem is due to how version 2.2 saves the configuration following the https://www.drupal.org/project/anonymous_login/issues/3389754 Store paths as an array Fixed feature.

    However, I can confirm that by uninstalling and reinstalling the module in the chosen version and re-filling the form with the desired configuration, the module works correctly.

  • 🇺🇸United States seanr

    FWIW, I was able to simply save the config page and re-export the config. Following that, deploys work fine without causing the warning.

  • 🇦🇹Austria golubovicm

    Older version is saving paths config like:
    paths: "~/api/*\r\n/admin*
    while newer is saving it as array:

    paths:
      - '~/api/*'
      - '/admin*'

    So, after module update it's enough to go to module's config page, save the config, eventually clear the cache and it will start working.
    And if you have config somewhere in old format on your side that's being imported during the builds it has to be adjusted to new format.

Production build 0.71.5 2024