magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.55k stars 9.32k forks source link

EAV module may generate deprecation error under PHP 8.1 #35856

Closed speller closed 2 years ago

speller commented 2 years ago

Preconditions and environment

Steps to reproduce

Not really sure about the exact steps, but I'm checking for an attribute uniqueness before saving the customer user:

class Foo extends AbstractBackend
{
    protected function checkUniqueUsername(Customer $object)
    {
        $attribute = $this->getAttribute();
        $entity = $attribute->getEntity();
        if (!$entity->checkAttributeUniqueValue($attribute, $object)) {
            throw new AlreadyExistsException(__('Account with the same attribure already exist'));
        }
    }
}

Expected result

Work fine under 2.4.3 + PHP 7.4

Actual result

Deprecated Functionality: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /magento/vendor/magento/module-eav/Model/Entity/AbstractEntity.php on line 947

Additional information

No response

Release note

No response

Triage and priority

m2-assistant[bot] commented 2 years ago

Hi @speller. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

shikhamis11 commented 2 years ago

@magento give me 2.4-develop instance with edition ee

magento-deployment-service[bot] commented 2 years ago

Hi @shikhamis11. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 2 years ago

Hi @shikhamis11, here is your Magento Instance: https://ade592f006b0aee4d71631a7aaeac0ff.instances.magento-community.engineering Admin access: https://ade592f006b0aee4d71631a7aaeac0ff.instances.magento-community.engineering/admin_b9ce Login: 948641af Password: 1d16f0b0a50c

m2-assistant[bot] commented 2 years ago

Hi @engcom-Lima. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Lima commented 2 years ago

Hi @speller ,

Thanks for your contribution and collaboration.

Kindly provide us exact steps to reproduce the issue. May be issue got fixed in the latest branch as this kind of error Deprecated Functionality: trim(): Passing null to parameter #1 ($string) reported by many reporters. Please test in latest 2.4-develop of Magento and let us know if you are facing any issue.

Thanks

speller commented 2 years ago

@engcom-Lima I didn't test in the dev version yet. But I think the issue appears when the customer entity has a custom attribute but is saved without setting this attribute value.

I'm using the following code to add this attribute:

    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
        $this->logger->info("Installing Auth0 ID custom customer attribute.");
        $this->moduleDataSetup->getConnection()->startSetup();

        $this->customerSetup->addAttribute(
            Customer::ENTITY,
            Auth0Id::ATTR_NAME,
            [
                'type' => 'varchar',
                'label' => 'Auth0 ID',
                'input' => 'text',
                'backend' => Auth0Id::class,
                'required' => false,
                'visible' => false,
                'user_defined' => true,
                'unique' => true,
                'sort_order' => 150,
                'position' => 150,
                'system' => false,
            ]
        );

        $this->customerSetup->addAttributeToSet(
            CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER,
            CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER,
            null,
            Auth0Id::ATTR_NAME,
        );

        $attribute =
            $this->customerSetup->getEavConfig()
                ->getAttribute(Customer::ENTITY, Auth0Id::ATTR_NAME)
                ->addData([
                    'used_in_forms' => [
                        'adminhtml_customer',
                    ],
                    'is_used_in_grid' => 1,
                    'is_visible_in_grid' => 1,
                    'is_filterable_in_grid' => 1,
                    'is_searchable_in_grid' => 1,
                ]);
        $this->attributeResource->save($attribute);
        $this->moduleDataSetup->getConnection()->endSetup();
        $this->logger->info("Attribute Auth0 ID successfully installed.");
    }
m2-assistant[bot] commented 2 years ago

Hi @engcom-Hotel. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Hotel commented 2 years ago

Hello @speller,

Thanks for the report and collaboration!

We have tried to reproduce the issue in Magento's development branch i.e. 2-4-develop but for us the issue is not reproducible. We have made a custom module in order to reproduce the issue. The same is attached below:

Magz.zip

We have tried to reproduce the issue with PHP 8.1;

image

Please let us know in case we have missed anything.

Thanks

speller commented 2 years ago

@engcom-Hotel sorry for a late reply. I can confirm the issue is solved in 2.4.5. The line causing the warning was changed from

                'value' => trim($value),

to

                'value' => $value !== null ? trim($value) : '',
engcom-Hotel commented 2 years ago

Hello @speller,

Thanks for the conforming that issue has been resolved in the latest release version of Magento. Hence we are closing this issue.

Thanks