Problem/Motivation

If uid field on product or product_variation is overriden (e.g. core.base_field_override.commerce_product_variation.default.uid.yml) long time ago it could contain:

default_value_callback: 'Drupal\commerce_product\Entity\ProductVariation::getCurrentUserId'

But getCurrentUserId is deprecated now and removed in current Commerce, so on entity form it prints:

Warning: call_user_func() expects parameter 1 to be a valid callback, class 'Drupal\commerce_product\Entity\ProductVariation' does not have a method 'getCurrentUserId' in Drupal\Core\Field\FieldConfigBase->getDefaultValue() (line 397 file /app/web/core/lib/Drupal/Core/Field/FieldConfigBase.php).

And when tried to save it:

Column 'uid' cannot be null: INSERT INTO {commerce_product_variation_field_data} …

Proposed resolution

There should be update hook converting default_value_callback to getDefaultEntityOwner.

Workaround

Just change:

default_value_callback: 'Drupal\commerce_product\Entity\ProductVariation::getCurrentUserId'

to:

default_value_callback: 'Drupal\commerce_product\Entity\ProductVariation::getDefaultEntityOwner'

In both core.base_field_override.commerce_product_variation.*.uid.yml and core.base_field_override.commerce_product.*.uid.yml.

Issue fork commerce-3153399

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Bobík created an issue. See original summary.

jwwj’s picture

commerce_product_update_8210 should do this already, at least according to the code there? Did you run drupal update:execute (Drupal console) or the Drush equivalent?

vasike’s picture

Version: 8.x-2.x-dev » 3.0.x-dev

i can confirm the issue for 3.x and the solution from related core ticket

move the 3.x so we can work on it ... and then, maybe, backport ...

vasike’s picture

Status: Active » Needs review

MR created ...

vasike’s picture

MR updated ... as i missed Product variation

vasike’s picture

Reminder: Config files needs to be updated too ... to avoid this issues ... for good

core.base_field_override.commerce_product.default.uid.yml
core.base_field_override.commerce_product_variation.default.uid.yml

`

jsacksick’s picture

Status: Needs review » Needs work

Other post update functions are named like the following:

commerce_product_post_update_7(), so let's do commerce_product_post_update_8 for consistency.

Also the comment can probably say, Fix the "uid" default_value callback for product & variations.

vasike’s picture

Status: Needs work » Needs review

@jsacksick update MR
- renamed to commerce_product_post_update_8()
- add your comment suggestion.
- "remove code duplicate"

vensires made their first commit to this issue’s fork.

vensires’s picture

I have merged commits from master 3.0.x branch. Caution though for anyone who used the MR in the past! My fix changes commerce_product_post_update_8() to commerce_product_post_update_9() because commerce_product_post_update_8() was already used in a later commit to fix #3173426: Layout builder does not work when there is a product attribute without values.

PS: For anyone coming here due to a Column 'uid' cannot be null: INSERT INTO {commerce_product_variation_field_data} error, check if the Author field is displayed in the variation form. If it is, hide it. It seems to cause issues when creating the variation from Inline Entity Form, like when editing the variation from inside a product's add/edit form.