mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Upgrade from 2.8.x to 2.9.1: possible BC break for nullable behaviour #6736
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @jmsche on GitHub (May 25, 2021).
Hi everyone,
I just upgraded doctrine/orm to 2.9.1 (from 2.8.x) on a simple project.
It makes some columns that were previously not nullable, nullable (the Column annotation does not have "nullable" set to any value in 2.9, but from what I can see it was false by default until 2.8.x included).
I think the changes happened since these PRs: https://github.com/doctrine/orm/pull/8439 & https://github.com/doctrine/orm/pull/8589
I guess the changes happen because the property in my code is nullable, and as nullable is not defined in my Column annotation, the driver thinks it's nullable.
Is it considered a BC break?
Regards,
@zolex commented on GitHub (May 25, 2021):
I can confirm this behavior. also the
JoinColumn(nullable=true)seems to be ignored and also the migrations creates update table statements that set nullable to false where it should be true.@beberlei commented on GitHub (May 25, 2021):
I thought I adressed this with https://github.com/doctrine/orm/pull/8678 - can you check how this relates?
@jmsche commented on GitHub (May 25, 2021):
I think there are two different bugs here (but maybe related):
@Columnsetting nullable to true@JoinColumnwhich can't override nullable@dmaicher commented on GitHub (May 25, 2021):
Similar problem here with 2.9.1 (upgraded from 2.8.5):
I have an entity with a relation like
But since its using single table inheritance the column needs to be nullable. Only for this particular type its set. Now the
nullable=trueis ignored and I get a migration diff like@pieterw2w commented on GitHub (May 26, 2021):
same issue as dmaicher: the column is no longer nullable.
@TheKassaK commented on GitHub (May 26, 2021):
Same issue, downgraded to 2.8.5
@Lustmored commented on GitHub (May 27, 2021):
@beberlei I'm afraid #8678 introduced at least one part of this problem. Change in
lib/Doctrine/ORM/Mapping/ClassMetadataInfo.phpmade it overwritenullableattribute whenever non-nullable typed parameter is found.This is because when
nullableonJoinColumnannotation is non-nullable bool there is no way telling if it is being set by user or have default value and the overwrite happens every time.Solving it the right way would probably require
nullableonJoinColumnto be nullable again (and fighting strange bugs I didn't quite understood in other ORM parts) or using some other way to determine whether it was set or not or removing this rule and reintroduce it in 3.0 in some way that wouldn't enforce BC.I can try to pursue "some other way to determine whether it was set or not" option but I am a bit concerned about mapping drivers that don't use
JoinColumnclass (YAML/XML/PHP) - I have to investigate them before judging.@Lustmored commented on GitHub (May 27, 2021):
I have created draft of the possible solution that minimizes BC impact and fixes overwriting
nullableparameter. I would love getting some feedback before working on remaining drivers.This however does not change default
@Columnbehavior as it seems to defy it's purpose. Non-nullable typed property should in my opinion be not nullable in database by default, because passing null to non-nullable property throwsTypeErroras far as I know.@dmaicher commented on GitHub (May 27, 2021):
@Lustmored but this is tricky when talking about single table entity inheritance as in my case mentioned above. There the column needs to be nullable for other types of the entity although its property is typed and not nullable
@Lustmored commented on GitHub (May 27, 2021):
This is covered by my draft change where in your example column will still be nullable. The change is about defaults and it failed with
JoinColumn, where defaults were enforced by mistake.So your example:
will work with my draft, while:
will still default to
nullable: false).Hope that makes it clear :) I'm no expert here, so possibly this approach have some drawbacks too.
@beberlei commented on GitHub (May 29, 2021):
I will look into this and @Lustmored draft PR the coming days, this has highest priority to fix with a release planned for next week.
@Lustmored commented on GitHub (May 29, 2021):
I can manage time to work on this PR on Monday, so if idea behind it seems right let me know and I'll finish it.
@beberlei commented on GitHub (May 31, 2021):
I think we need to remove the nullable/ˋallowsNullˋ code completely, because as said you might want toconfigure this differently in DB and code
@Lustmored commented on GitHub (May 31, 2021):
@beberlei How do you feel about leaving this logic only for Attribute driver? It is new in 2.9 (no BC break), requires PHP8 (so typed properties will be common there) and could simply be useful to new users. I could get working PR today.
Otherwise - is this change something you'd like to see for ORM 3?
@zolex commented on GitHub (May 31, 2021):
I don't think it's good idea to have different logic for the same definitions in annotations and attributes.
@beberlei commented on GitHub (May 31, 2021):
I agree with @zolex the logic should be consistent across drivers. We could look into this for ORM 3 though. At least if nullable is not set and the field allows null, then nullable should default to true. A user could always change it back to be nullable=false.
@Lustmored commented on GitHub (May 31, 2021):
All right, thanks for the answer. I will work towards PR targeting 3.0 👍