{"action":"created","issue":{"url":"https://api.github.com/repos/magento/magento2/issues/6411","repository_url":"https://api.github.com/repos/magento/magento2","labels_url":"https://api.github.com/repos/magento/magento2/issues/6411/labels{/name}","comments_url":"https://api.github.com/repos/magento/magento2/issues/6411/comments","events_url":"https://api.github.com/repos/magento/magento2/issues/6411/events","html_url":"https://github.com/magento/magento2/issues/6411","id":174211020,"number":6411,"title":"Customer Address Custom Attribute gets deleted upon update","user":{"login":"marcoreni","id":2797489,"avatar_url":"https://avatars.githubusercontent.com/u/2797489?v=3","gravatar_id":"","url":"https://api.github.com/users/marcoreni","html_url":"https://github.com/marcoreni","followers_url":"https://api.github.com/users/marcoreni/followers","following_url":"https://api.github.com/users/marcoreni/following{/other_user}","gists_url":"https://api.github.com/users/marcoreni/gists{/gist_id}","starred_url":"https://api.github.com/users/marcoreni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcoreni/subscriptions","organizations_url":"https://api.github.com/users/marcoreni/orgs","repos_url":"https://api.github.com/users/marcoreni/repos","events_url":"https://api.github.com/users/marcoreni/events{/privacy}","received_events_url":"https://api.github.com/users/marcoreni/received_events","type":"User","site_admin":false},"labels":[{"id":429635502,"url":"https://api.github.com/repos/magento/magento2/labels/2.1.x","name":"2.1.x","color":"fbca04","default":false},{"id":147131376,"url":"https://api.github.com/repos/magento/magento2/labels/bug%20report","name":"bug report","color":"d93f0b","default":false},{"id":374015207,"url":"https://api.github.com/repos/magento/magento2/labels/Customer","name":"Customer","color":"1d76db","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-08-31T08:13:20Z","updated_at":"2016-11-09T07:19:16Z","closed_at":null,"body":"<!--- Provide a general summary of the issue in the Title above -->\n\n<!--- Before adding new issues, please, check this article https://github.com/magento/magento2/wiki/Issue-reporting-guidelines-->\n### Preconditions\n\n<!--- Provide a more detailed information of environment you use -->\n\n<!--- Magento version, tag, HEAD, etc., PHP & MySQL version, etc.. -->\n1. Magento 2.1.0 CE, php 7.0.8\n### Steps to reproduce\n1. Define new Customer Address Custom Attribute in UpgradeData:\n\n``` php\n$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);\n$addressEntity = $customerSetup->getEavConfig()->getEntityType('customer_address');\n$attributeSetId = $addressEntity->getDefaultAttributeSetId();\n\n/** @var AttributeSet $attributeSet  */\n$attributeSet = $this->attributeSetFactory->create();\n$attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);\n\n$customerSetup->addAttribute('customer_address','attribute_test',[\n                'type'          => 'varchar',\n                'label'         => 'Attribute Test',\n                'input'         => 'text',\n                'required'      => false,\n\n                'visible'       => true,\n                'user_defined'  => false,\n                'position'      => 200,\n                'sort_order'    => 200,\n                'system'        => false,\n            ]);\n\n$attr1 = $customerSetup->getEavConfig()->getAttribute('customer_address', 'attribute_test');\n$attr1->addData($customerAddressData = [\n                'attribute_set_id' => $attributeSetId,\n                'attribute_group_id' => $attributeGroupId,\n                'used_in_forms' => ['adminhtml_customer_address']);\n$this->attributeRepository->save($attr1);\n```\n1. Populate the attribute through adminhtml interface. The attribute is correctly persisted on EAV tables\n2. Intercept the LoginPost action with a beforeExecute(), then retrieve and save customer without modifications:\n\n``` php\n$customer = $this->customerRepositoryInterface->get($login['username']);\n$this->customerRepositoryInterface->save($customer);\nreturn;\n```\n### Expected result\n\n<!--- Tell us what should happen -->\n1. The Custom Attribute should stay there.\n### Actual result\n\n<!--- Tell us what happens instead -->\n1. The Custom Attribute gets deleted\n\nIt seems that the problem may reside in Magento\\Customer\\Model\\ResourceModel\\Customer\\Relation.php:49 which uses $address->save() instead of the repository (thus not having an attribute_set_id set), but if I remove the ->save($customer)  in the plugin everything works as expected.\n"},"comment":{"url":"https://api.github.com/repos/magento/magento2/issues/comments/259348664","html_url":"https://github.com/magento/magento2/issues/6411#issuecomment-259348664","issue_url":"https://api.github.com/repos/magento/magento2/issues/6411","id":259348664,"user":{"login":"rzinnatullin","id":11244866,"avatar_url":"https://avatars.githubusercontent.com/u/11244866?v=3","gravatar_id":"","url":"https://api.github.com/users/rzinnatullin","html_url":"https://github.com/rzinnatullin","followers_url":"https://api.github.com/users/rzinnatullin/followers","following_url":"https://api.github.com/users/rzinnatullin/following{/other_user}","gists_url":"https://api.github.com/users/rzinnatullin/gists{/gist_id}","starred_url":"https://api.github.com/users/rzinnatullin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rzinnatullin/subscriptions","organizations_url":"https://api.github.com/users/rzinnatullin/orgs","repos_url":"https://api.github.com/users/rzinnatullin/repos","events_url":"https://api.github.com/users/rzinnatullin/events{/privacy}","received_events_url":"https://api.github.com/users/rzinnatullin/received_events","type":"User","site_admin":false},"created_at":"2016-11-09T07:19:16Z","updated_at":"2016-11-09T07:19:16Z","body":"In my case the reproduction steps are the same as @marcoreni described, but instead of resaving a customer I do this:\r\n```php\r\n    $addr = $this->addressFactory->create()->load($addressId);\r\n    $addr->setAttributeTest('test');\r\n    $addr->save();\r\n```\r\nTo workaround the issue I put `$addr->setAttributeSetId(2)` before `$addr->save()`\r\n"}}
{"actor":{"display_login":"rzinnatullin"}}