Problem/Motivation

EntityReferenceFieldTest fails currently with PostgreSQL as database backend.

The Entity unit tests attempt to assign an integer for entity from 1 to 0xFFFFFFFF, but this is greater than the maximum size for integers in PostgreSQL. See Numeric DataType specification.

Test Backtrace:

Drupal\Core\Entity\EntityStorageException: SQLSTATE[22003]: Numeric value out of range: 7 ERROR: value "2620798132" is out of range for type integer LINE 1: ...3019entity_test_update_id_seq', GREATEST(MAX(id), '262079813... ^ in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 934 of /var/www/drupal8.dev/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object)
Drupal\Core\Entity\Entity->save()
Drupal\system\Tests\Entity\EntityReferenceFieldTest->testTargetEntityNoLoad()

Proposed resolution

Change the value from 0XFFFFFFFF to 0x7FFFFFF instead. This affects test only.

Database Maximum Safe Integer
MySQL 0XFFFFFFFF
SQLite 0X7FFFFFFFFFFFFFFF
PostgreSQL 0x7FFFFFFF
SQL Server 2014 0x7FFFFFFF
Oracle 10 0x7FFFFFFF

Remaining tasks

Write patch.

User interface changes

None.

API changes

None.

CommentFileSizeAuthor
#16 2443655-16.patch903 bytesdaffie
#10 2443655-10.patch937 bytesdaffie
#6 2443655-6.patch692 bytesdaffie
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bzrudi71’s picture

This seems like a random exception. Can't reproduce locally and got pass on testbpt also. We should keep an eye on this...

mradcliffe’s picture

Issue summary: View changes

I ran this on my vagrant vm running debian with the above result.

bzrudi71’s picture

Ah yes, that explains the random - nice. Should we really complicate things more than needed? I mean, it's just about creating a random value so why not using a value of 7FFFFFFF (int 2147483647) instead? That should be save enough for having some randomness and is save for all types of databases I guess :-)

Berdir’s picture

Agreed, let's just use a max value that works for all database backends, should be a trivial fix then?

mradcliffe’s picture

Issue summary: View changes
Issue tags: +mssql sqlsrv, +oracle, +Novice

Yes, that makes sense. Oracle, SQL Server, and PostgreSQL all have the same maximum signed integer (bigints obviously bigger). SQLite is absurdly large.

daffie’s picture

Status: Active » Needs review
FileSize
692 bytes
anksy’s picture

Status: Needs review » Reviewed & tested by the community

Tested the patch successfully. The tests don't throw any error.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Let's a comment to explain how the value is arrived at.

mradcliffe’s picture

I was reading the patch on the bus this morning, and wondering the same thing about the need for a comment.

daffie’s picture

Status: Needs work » Needs review
FileSize
937 bytes

Comment added.

anksy’s picture

@daffie : Shouldn't the comment say "The value 0x7FFFFFFF is the maximum integer value that is ..." instead of lowest maximum integer value ...

bzrudi71’s picture

@anksy: It's not wrong to say the lowest maximum value, as MySQL and SQLite allow for higher int values, so would something like this explain it better?

0x7FFFFFFF is the maximum allowed value for integers that works for all Drupal supported databases and is known to work for other databases like SQL Server 2014 and Oracle 10 too.

anksy’s picture

@bzrudi71 Yeah that explains it clearly. Its better.

daffie’s picture

@anksy: Can you do a review of the patch?

anksy’s picture

@daffie so should we change the comment as bzrudi71 suggested or keep it the same?

daffie’s picture

FileSize
903 bytes

0x7FFFFFFF is the maximum allowed value for integers that works for all Drupal supported databases and is known to work for other databases like SQL Server 2014 and Oracle 10 too.

I think that the text from bzrudi71 is better.

tstoeckler’s picture

Status: Needs review » Reviewed & tested by the community

looks good.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.0.x. Thanks!

  • webchick committed 501409f on 8.0.x
    Issue #2443655 by daffie, bzrudi71: PostgreSQL: Fix system\Tests\Entity\...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.