Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

21842: don't cache absolute file paths in validator factory #21856

Conversation

david-fuehr
Copy link
Contributor

@david-fuehr david-fuehr commented Mar 20, 2019

Description

This issue comes from Magento\Framework\Validator\Factory::_initializeConfigList where absolute file paths are cached. The actual file content is evaluated using the local file system.

The method is used in \Magento\Customer\Model\ResourceModel\Address::_validate, \Magento\Quote\Model\CustomerManagement::validateAddresses and \Magento\Customer\Model\ResourceModel\Customer::_validate and thus an error (The "/<abs_instance_path>/app/code/Magento/Eav/etc/validation.xml" file doesn't exist.) occurs whenever a customer, a customer_address or quote for a registered customer is saved.

Fixed Issues

  1. Checkout error for registered customer with cache_id_prefix on multi server setup #21842: Checkout error for registered customer with cache_id_prefix on multi server setup

Manual testing scenarios

most realistic scenario

  1. have a multi server setup with
    1. node backend (absolute instance dir: /var/www/backend/release/2019-02-28)
    2. node frontend-a (absolute instance dir: /var/www/frontend/release/2019-02-28)
    3. node frontend-b (absolute instance dir: /var/www/frontend/release/2019-03-01 - autospawned)
    4. node redis
    5. share cache for all Magento instances (identical id_prefix in cache section of env.php)
    6. [node mysql, ...]
  2. clear cache on backend node
  3. right after that save a customer or customer_address on the backend node (may be a cron job or similar)
  4. place an order with a registered customer on one of the frontend-nodes
    1.expected: The success page is being shown

simplified repro steps

  1. set up a regular instance
  2. make sure that the id_prefix in env.php is defined
    'cache' => [
        'frontend' => [
            'default' => [
                'id_prefix' => '173_'
            ],
            'page_cache' => [
                'id_prefix' => '173_'
            ]
        ]
    ],
  1. redis may be used, the issue can also be reproduced using file based caching
  2. register a customer
  3. place an order using this customer
  4. move the instance directory to another path
  5. update webserver configuration accordingly and restart
  6. try to place an order with the same customer again
    1. expected: success page is being shown

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)
  • All automated tests passed successfully (all builds on Travis CI are green)

Github issue: magento#21842

In customer and customer_address validation context the validator
factory no longer caches absolute file paths for the validation.xml
files (currently two file) as the file content is evaluated later
in the filesystem directly and the file paths may not be correct
in a multi server setup with shared cache (id_prefix)
- adapt unit test
@magento-engcom-team
Copy link
Contributor

Hi @david-fuehr. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

- refactoring of static method use should be in a separate pull request
@magento-engcom-team
Copy link
Contributor

Hi @larsroettig, thank you for the review.
ENGCOM-4545 has been created to process this Pull Request

class Factory
{
/** cache key */
const CACHE_KEY = __CLASS__;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, we are not allowed to remove the constants according to our Backward Compatible Development Guide. Just mark it as deprecated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback. I addressed this in my latest commit.

*/
protected $_configFiles = null;
protected $_configFiles;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't change the default value of public/protected properties according to our Backward Compatible Development Guide. Just mark it as deprecated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback. I addressed this in my latest commit.

*/
public function __construct(
\Magento\Framework\ObjectManagerInterface $objectManager,
\Magento\Framework\Module\Dir\Reader $moduleReader,
FrontendInterface $cache
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, leave FrontendInterface as constructor parameter and mark it as deprecated, otherwise it's backward incompatible change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback. I addressed this in my latest commit.

@magento-engcom-team
Copy link
Contributor

Hi @sivaschenko, thank you for the review.
ENGCOM-4545 has been created to process this Pull Request

@VasylShvorak
Copy link
Contributor

✔️ QA passed

@m2-assistant
Copy link

m2-assistant bot commented Apr 29, 2019

Hi @david-fuehr, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants