-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[PropertyInfo] DoctrineExtractor incompatible type resolution with DBAL 4 or ORM 2.19 #54418
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
Comments
DoctrineExtractor should be updated to account for the new DBAL 4 behavior for the Bigint type. PRs are welcome. |
I don't mind opening a PR with my initial idea, contributors can nuke me there with their feedback 😄 The main problem is this fallback behavior between types that cannot be correctly reflected with In any case, I am cheating a bit because I am using this issue as a way to catalog my findings into this since I spent ~3 to ~5 hours trying to make Doctrine + Sf Serializer + Api Platform happy 😅 |
…INT type (llupa) This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [PropertyInfo] Update DoctrineExtractor for new DBAL 4 BIGINT type | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | not sure | Deprecations? | no | Issues | Fix #54418 | License | MIT ## Additional Considerations This issue looks pretty straight forward, but it has had me running in circles not being sure how to exactly interpret it. The new return type to make it work with DBAL 4 is _fine_, but it is neither an intersection nor a union type, which **will** cause trouble for other libs if they do not explicitly check each. There is not easy way to get which DBAL version is the extractor is running against, so trying to optimize the flow is _tricky_. I am opening this PR to have a starting point in the hopes that maintainers of this package have more historical context than me. I have tried to document as much as possible about this in the issue linked above. 🍻 Commits ------- 92e54ac [PropertyInfo] Update DoctrineExtractor for new DBAL 4 BIGINT type
I have the same issue regardless of the merged fix. Having a property defined like
Denormalizing an array to this object
Results in
Symfony Version is 6.4.9 $typeOfField is "decimal" in my case. |
@sophie-kuehn Please open a new issue and provide a small example application that allows to reproduce it. |
Symfony version(s) affected
7.0.3
Description
Preface
With the recent release of Doctrine ORM 3 and DBAL 4 there has been a major change in at least one column type.
bigint now reads:
Additionally, if you did not yet make the jump to ORM 3/DBAL 4 and are using ORM 2.19 which acts like Sf
.4
and thenext major
.0
you can useint
typehints in your PHP code with abigint
column type if you go for astring|int
union. You can read more about it in this issue: Invalid field error reported for bigint DBAL type.
Another case would be if you know that your project's tech will always rely on
int
within yourPHP_INT_MAX
you couldalso override the default
bigint
type and bind it toint
.This is also dependent of your DB engine too, but generally speaking, all of the above are true for pgsql. How one goes about handling this Doctrine hiccup is up to developer's choice and from my POV any of the solutions that can be used for Doctrine is fine.
Symfony
Let's assume that you are using one of the methods to have Doctrine happy but without jeopardising your project. If your project is in any capacity in need of denormalizing request data into PHP objects this is the next step that breaks.
At one point, for objects, the
AbstractObjectNormalizer::getTypes()
is called, which in turn makes use ofPropertyInfoExtractor
to resolve theType
of abigint
property that is in some way type-hinted asint
and request data will useint
values too.DoctrineExtractor::getTypes()
will internally try to get the PHP type ofbigint
which for now is always going to mapit to
string
.This causes a gate-keeping effect with the following exception message:
The type of the "bigint" attribute for class "IHaveNumbers" must be one of "string" ("int" given).
For this there are some possible ways to go about it.
A) You can use
DISABLE_TYPE_ENFORCEMENT
on your context and the value is used as is, letting it be handled on code levelwhich may result in
\Error
issues.B) Switch your property to
string
only and add more cast juggling.C) Switch your property to
string
and also reflect this in your general API so that request data is now onlystring
.D) Update / Decorate
DoctrineExtractor
with the following hack solution:I went for option D because I really want to have
bigint
typed toint
and not tostring
as I have a project thatonly delivers an API with API Platform. So keeping my JSON Schema consistent is top priority.
It works, but I am not sure if it is a) a solution and b) a preferred solution.
How to reproduce
I can create a simple project if the description above is not enough. The easiest way would be to:
Possible Solution
In case
DoctrineExtractor
cannot be updated one can also play around with attributes. Below I have my example in my project:Additional Context
No response
The text was updated successfully, but these errors were encountered: