Skip to content

loadAllAttributes fails for EAV entities #5339

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

Closed
maderlock opened this issue Jun 29, 2016 · 11 comments
Closed

loadAllAttributes fails for EAV entities #5339

maderlock opened this issue Jun 29, 2016 · 11 comments
Labels
bug report Component: Eav Fixed in 2.2.x The issue has been fixed in 2.2 release line Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed

Comments

@maderlock
Copy link

maderlock commented Jun 29, 2016

Preconditions

Magento 2.1.0

Steps to reproduce

  1. Install Magento 2.1.0
  2. Create a new EAV entity type 'my_eav_attr' with static and non-static attributes
  3. During run-time, create an instance of a collection that extends Magento\Eav\Model\Entity\Collection\AbstractCollection
  4. Call addAttributeToSelect('*') on collection

Expected result

  1. A valid collection (as worked in 2.0.7)

Actual result

main.CRITICAL: Exception: Serialization of 'Magento\Framework\View\Layout\Element' is not allowed in .../vendor/magento/module-eav/Model/Entity/AttributeCache.php:116
Stack trace:
#0 .../vendor/magento/module-eav/Model/Entity/AttributeCache.php(116): serialize(Array)
#1 .../vendor/magento/module-eav/Model/Entity/AttributeLoader.php(98): Magento\Eav\Model\Entity\AttributeCache->saveAttributes('my_eav_attr', Array)
#2 .../vendor/magento/module-eav/Model/Entity/AbstractEntity.php(510): Magento\Eav\Model\Entity\AttributeLoader->loadAllAttributes(Object(MyModule\MyEAVType\Model\ResourceModel\Tile\Interceptor), NULL)
#3 .../var/generation/MyModule/MyEAVType/Model/ResourceModel/Tile/Interceptor.php(193): Magento\Eav\Model\Entity\AbstractEntity->loadAllAttributes(NULL)
#4 .../vendor/magento/module-eav/Model/Entity/Collection/AbstractCollection.php(484): MyModule\MyEAVType\Model\ResourceModel\MyEAVType\Interceptor->loadAllAttributes()
#5 .../app/code/MyModule/MyEAVType/view/frontend/templates/myblock.phtml(6): Magento\Eav\Model\Entity\Collection\AbstractCollection->addAttributeToSelect('*')

Debugging in the attribute cache, it appears that serialisation of the static attributes is failing, although it's fine for the non-static attributes.

I've seen a suggestion that this is not an issue if I specify exactly which attributes I want, which is true, but the point of using EAV is that at compile time I will not always know the complete set of attributes I need.

@maderlock
Copy link
Author

As a temporary measure I've had to exclude my EAV entity from attribute caching via di.xml:

  <type name="Magento\Eav\Model\Entity\AttributeCache">
        <arguments>
            <argument name="unsupportedTypes" xsi:type="array">
                <item name="0" xsi:type="string">my_eav_attr</item>
            </argument>
        </arguments>
    </type>

@jessetaverne
Copy link

jessetaverne commented Jul 1, 2016

I experience the same issue after upgrading to M2.1

edit:
My temp fix is to just disable the EAV caching type
I'm running Community Edition

@AntonEvers
Copy link
Contributor

AntonEvers commented Jul 4, 2016

I'm running Magento EE 2.1.0 and I have the same issue since the upgrade with addAttributeToSelect('*') on custom entity collections.

@koenner01
Copy link
Contributor

This also has something to do with the mode in which Magento is running.
I'm having the same issue when running in developer mode, but in production mode this is not an issue

@philipvandebriel
Copy link

Hi,

We have the same problem after upgrading to magento CE 2.1.1

@romainruaud
Copy link
Contributor

Same issue for me. Magento CE 2.1.1 and Magento EE 2.1.1

@romainruaud
Copy link
Contributor

@maderlock I managed to get it working on custom entity attributes by reporting this line : https://github.com/magento/magento2/blob/develop/app/code/Magento/Catalog/Model/ResourceModel/Eav/Attribute.php#L827

to my attributes.

I think the "raw" EAV attributes are not usable "as is", because when looking at catalog eav attributes, they add a lot of code to get them working. There is this one regarding the __sleep() method but also custom methods to have a working scoping for attribute values.

Regards

@Tjitse-E
Copy link
Contributor

I have the same issue after upgrading to CE 2.1.1. @jessetaverne temporary fix worked for me, thanks.

@AntonEvers
Copy link
Contributor

Yes I also fixed this by creating my own attribute model and adding the unsetData at __sleep():

<?php

namespace Example\Module\Model\Entity;

/**
 * Class Attribute
 * @package Example\Module\Model\Entity
 */
class Attribute extends \Magento\Eav\Model\Entity\Attribute
{
    /**
     * This fixes https://github.com/magento/magento2/issues/5339
     *
     * @inheritdoc
     */
    public function __sleep()
    {
        $this->unsetData('entity_type');
        return parent::__sleep();
    }
}

And after that putting this model in the eav_entity_type table (attribute model = "Example\Module\Model\Entity\Attribute" with my custom entity. This solves the issue like @romainruaud said.

@kanduvisla
Copy link
Contributor

I'm having this same problem in CE 2.1.7 when I extend \Magento\Catalog\Model\ResourceModel\Eav\Attribute and add an extra dependency to the constructor. The __sleep()-fix doesn't work, since it's parent class is already doing the same.

@magento-engcom-team magento-engcom-team added bug report Component: Eav Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed and removed Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed labels Sep 11, 2017
@orlangur
Copy link
Contributor

Buggy EAV Attribute Cache mechanism was removed on Magento 2.2.0 branch: 3ae7c19

This is not something that could be backported due to BC constraints, as a workaround you can try just to disable this cache type.

@orlangur orlangur added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Sep 21, 2017
magento-engcom-team pushed a commit that referenced this issue Feb 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Component: Eav Fixed in 2.2.x The issue has been fixed in 2.2 release line Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed
Projects
None yet
Development

No branches or pull requests