Skip to content

fix(config): capture config value before beforeSave() transforms it for lock-env#40541

Open
lbajsarowicz wants to merge 1 commit intomagento:2.4-developfrom
lbajsarowicz:fix/39836-config-set-lock-env-array-value
Open

fix(config): capture config value before beforeSave() transforms it for lock-env#40541
lbajsarowicz wants to merge 1 commit intomagento:2.4-developfrom
lbajsarowicz:fix/39836-config-set-lock-env-array-value

Conversation

@lbajsarowicz
Copy link
Contributor

Description (*)

When using bin/magento config:set --lock-env, the LockProcessor was capturing the configuration value after calling beforeSave() on the backend model. Some backend models transform the value in beforeSave() for database serialization (e.g. converting a comma-separated string to an array). This caused the DB-serialized form (e.g. an array) to be written to env.php, making subsequent reads return the wrong type.

Example error:

Type Error occurred when creating object: Magento\TwoFactorAuth\Model\Provider\Engine\DuoSecurity
explode(): Argument #2 ($string) must be of type string, array given

Root cause: After bin/magento config:set --lock-env twofactorauth/general/force_providers google, env.php incorrectly stored ['google'] (array) instead of 'google' (string) because ForceProviders::beforeSave() transforms the value for database storage.

Fix: Capture the value before beforeSave() is called. The beforeSave() lifecycle hook is intended for database serialization and should not affect what is stored in env.php. The validateBeforeSave() call remains first to still run all validations.

Related Pull Requests

No related pull requests

Fixed Issues

Fixes #39836

Manual testing scenarios (*)

  1. Run bin/magento config:set --lock-env twofactorauth/general/force_providers google
  2. Verify env.php contains 'force_providers' => 'google' (string, not array)
  3. Run bin/magento and confirm no errors about explode() receiving array instead of string

Questions or comments

No questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

⭐ Support my work

Do you like the fix? Remember to react with "👍🏻" to get it merged faster,
Then Sponsor me on Github so I can spend more time on fixing issues like this one.

Learn more at https://github.com/sponsors/lbajsarowicz

…or lock-env

When using `bin/magento config:set --lock-env`, the LockProcessor was
capturing the value AFTER calling beforeSave() on the backend model.
Some backend models transform the value in beforeSave() for database
serialization (e.g. converting a comma-separated string to an array).
This caused the DB-serialized form (e.g. an array) to be written to
env.php, making subsequent reads from env.php return the wrong type
and causing errors like:

  explode(): Argument magento#2 ($string) must be of type string, array given

Fixed by capturing the value before beforeSave() is called, so env.php
receives the scalar value rather than the DB-serialized form.

Fixes magento#39836
@m2-assistant
Copy link

m2-assistant bot commented Feb 18, 2026

Hi @lbajsarowicz. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.
❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names.

Allowed build names are:
  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

@lbajsarowicz
Copy link
Contributor Author

@magento run all tests

@engcom-Bravo engcom-Bravo added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Feb 19, 2026
@github-project-automation github-project-automation bot moved this to Pending Review in Pull Requests Dashboard Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: pending review

Projects

Status: Pending Review

Development

Successfully merging this pull request may close these issues.

Use of --lock-env on bin/magento config:set twofactorauth/general/force_providers results in bin/magento errors

2 participants