Problem/Motivation

Generally there's a 32 char limit to entity type names (machine names).
Unfortunately commerce_coupon_usage_transaction is 33 chars long. Which makes it basically incompatible with the core limitations. And as contrib modules often respect this limitations the same applies for contrib.
In my current case it is Entity Modified that complains.

Proposed resolution

As this is a limitation imposed by core we should fix it here and not e.g. in Entity Modified.
So way to go is rename commerce_coupon_usage_transaction to e.g. commerce_coupon_usage_trans.
I suggest to rename everything and not just the name of the entity type to keep consistency.
I hope this is possible - as 2.x still is in beta.

Attached patch has all the occurrences renamed and provides a update hook that renames the db table if necessary.

Remaining tasks

Reviews needed.

User interface changes

API changes

Entity type related things will break!
Customized views may break!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Status: Needs review » Needs work

The last submitted patch, commerce_coupon-entity_type-too-long.patch, failed testing.

das-peter’s picture

Status: Needs work » Needs review
FileSize
11.15 KB

Re-rolled, hope this one applies.

Status: Needs review » Needs work

The last submitted patch, 2: commerce_coupon-entity_type-too-long-2440857-1.patch, failed testing.

das-peter’s picture

Status: Needs work » Needs review
FileSize
11.66 KB

Re-rolled

torgosPizza’s picture

Is there a way someone like me can test this patch's effectiveness? We are having some odd bugs with Coupons but I won't know if this patch fixes them - can you tell me more about what kinds of issues might result with an entity machine name that's too long?

torgosPizza’s picture

I'm testing this on production and the patch applied cleanly, however I did get these errors when running drush updb:

array_keys() expects parameter 1 to be array, null given in common.inc:7154

Invalid argument supplied for foreach() entity.info.inc:151

These appear to have to do with a schema relationship but, as far as I can tell, everything seems to work fine despite the errors.

das-peter’s picture

What kinds of issues might result with an entity machine name that's too long?

Well e.g. Entity Modified has an own table in which it stores the modification time of entities - to do so it needs to match entity_type, entity_id, entity_revision and the timestamp.
The table uses a 32 char field for entity_type - as entity type should be 32 char - now if you try to store something longer than 32 chars this will lead to a DB error.

These appear to have to do with a schema relationship but, as far as I can tell, everything seems to work fine despite the errors.

Did you have custom views? Any leftovers of commerce_coupon_usage_transaction in your code / config?

torgosPizza’s picture

Status: Needs review » Reviewed & tested by the community

I never saw the errors mentioned as the reason for the patch but we've been using it in production with no issues. Suggest committing it.

torgosPizza’s picture

Status: Reviewed & tested by the community » Needs work

Looks like this patch no longer applies to the latest dev, as the usage.views.inc stuff fails and the rest needs an offset.

Also I wonder if instead of commerce_coupon_usage_trans we name it commerce_coupon_usage_txn which makes more sense to me.

kevster’s picture

I tried applying this to 7.x-2.0-rc2 and although it ran the update I had other errors - a bunch of these:

Invalid argument supplied for foreach() common.inc:7176 [warning]
array_keys() expects parameter 1 to be array, null given [warning]
common.inc:7196

Also didnt fix issue and caused other errors re the table name change so I rolled back and applied this patch to entity_modified https://www.drupal.org/node/2538760.

Im not sure why this error popped up - only change I can think of was a new discount was added which because the compatibility with other discounts option for this discount not compat with doesnt work I have to choose "This discount is compatible with any discount except the selected discounts." and then add all others - maybe this data was too long for saving?

My client lost 14 orders over the weekend due to this bug popping up and orders with discounts not being able to be processed...

Latest dev may be ok without the entity_modified patch but beware using this patch on RC2 as it didnt work for me...

johnle’s picture

Updated the patch for step #4 to the current dev release. I've been running into the same issues using the entity_admin module. Tested out the patch and it seem to be working without any issues using a coupon in the checkout process now.

bfodeke’s picture

Status: Needs work » Needs review
jcisio’s picture

Status: Needs review » Closed (works as designed)

They are fixing it in entity_modified #2538760: Increase entity_type column to 64.