Skip to content
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

Supply default values for optional values in sequence mapping if omitted by driver. #6683

Merged
merged 1 commit into from
Nov 26, 2017

Conversation

alextech
Copy link
Contributor

@alextech alextech commented Sep 3, 2017

Fix #6682
Cannot figure out how to get XML to run properly from Ticket directory as in contributor guide. If this is a strict requirement will try again. Figured out.

'allocationSize' => (string) $seqGenerator['allocation-size'],
'initialValue' => (string) $seqGenerator['initial-value']
'allocationSize' => (int) $seqGenerator['allocation-size'],
'initialValue' => (int) $seqGenerator['initial-value']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tbh, sequences are not necessarily int-based

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They can be floats? I do not think I can do CREATE SEQUENCE INCREMENT with anything but integer. Neither PostgreSQL, nor oracle https://docs.oracle.com/database/121/SQLRF/statements_6017.htm#SQLRF01314

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Postgres only supports bigint:

Sequences are based on bigint arithmetic, so the range cannot exceed the range of an eight-byte integer (-9223372036854775808 to 9223372036854775807).
https://www.postgresql.org/docs/9.5/static/sql-createsequence.html

But on 32-bit platform, bigint would be string/float...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. That would be still on PostgreSQL side though. The bug at highlighted line in referenced issue is in PHP side, where SequenceGenerator trying to predict maximum value. It is expecting PHP integer, as enforced by the cast, to do the addition for the prediction. But if value comes from XML parser, prediction calculation fails having second addend being string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or are you saying because of this 32-bit corner case, the schema mapping should not be touched, but the cast should be fixed instead wherever the parameters are used? In this case, are you saying xml parser is not root cause, that SequenceGenerator should be fixed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also turns out migrations wants the value to be string. If driver casts to integer itself, migration diff generates INCREMENT BY 0. Unit tests here do not notice that potential regression. so I guess the crash is better fixed at the SequenceGenerator level.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, discovered actual root cause. Thanks @Majkl578 for making me think further about it. Turns out xml driver is not supplying default values for optional fields when they are omitted in mapping file. This results in empty $definition keys, which causes "non numeric value" error during addition, not because it is a casting problem as I originally thought.

Will redo the fix by either validating input in ClassMetadataInfo::setSequenceGeneratorDefinition where it already does a little bit of parsing validation for sequence_name, but not the other parameters, or maybe I can find why XSD schema is not applied by XML driver.

@alextech alextech force-pushed the bugfix/xml_sequence_params branch from c96fc53 to 79becf3 Compare September 5, 2017 23:11
@alextech alextech changed the title Cast sequence parameters as integers in XML driver. Supply default values for sequence mapping if omitted by driver. Sep 5, 2017
@alextech alextech changed the title Supply default values for sequence mapping if omitted by driver. Supply default values for optional values in sequence mapping if omitted by driver. Sep 5, 2017
@alextech alextech force-pushed the bugfix/xml_sequence_params branch from 79becf3 to bfcab4d Compare September 5, 2017 23:32
@alextech
Copy link
Contributor Author

alextech commented Sep 6, 2017

Kept default as string too as @Ocramius suggested, however I will still point out that

  1. If plan to later convert to PHP 7 type syntax, SequenceGenerator constructor https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Id/SequenceGenerator.php#L63 wants an integer and will not be happy with string.
  2. xsd schema claims it to be integer so IMO it should throw exception if non_numeric value is given by user.

Supply default values for allocationSize and initialValue optional parameters.

Related to: doctrine#6682
@lcobucci lcobucci force-pushed the bugfix/xml_sequence_params branch from bfcab4d to b3331b2 Compare November 26, 2017 15:38
@lcobucci lcobucci added this to the 2.5.13 milestone Nov 26, 2017
@lcobucci lcobucci added the Bug label Nov 26, 2017
Copy link
Member

@lcobucci lcobucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've rebased the branch and applied some minor changes. It LGTM now!

@lcobucci
Copy link
Member

If plan to later convert to PHP 7 type syntax, SequenceGenerator constructor https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Id/SequenceGenerator.php#L63 wants an integer and will not be happy with string.

@alextech we only plan to add type declaration for v3 so that's fine for now, I'd say that's important to mimic the current behaviour in order to avoid BC breaks.

@lcobucci lcobucci merged commit 3ca65e2 into doctrine:master Nov 26, 2017
lcobucci added a commit to lcobucci/doctrine2 that referenced this pull request Nov 26, 2017
@lcobucci lcobucci self-assigned this Nov 26, 2017
@alextech
Copy link
Contributor Author

Thank you! I can now get off my custom branch.
@lcobucci sounds good. I am also seeing a very useful #6728 which is a great step, but I do not see it managing default values which is how these bugs occur. I do not know if it is validator's job to inject default values into driver, or driver should have defaults hardcoded in. ATM there is a disconnect between configuration passing schema validation, but the driver still expecting something else. So for v3 should the suggestion be made to have validator or parser pass in missing defaults, or do an "audit" of all driver components to ensure they do not crash without missing values?

@lcobucci
Copy link
Member

So for v3 should the suggestion be made to have validator or parser pass in missing defaults, or do an "audit" of all driver components to ensure they do not crash without missing values?

@alextech the best person to answer that would be @guilhermeblanco 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants