[PR #6533] #6499 commit order must consider non-nullability of join columns as prioritised over nullable join columns #10025

Open
opened 2026-01-22 16:06:10 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/6533

State: closed
Merged: No


As suggested by @lcobucci, I created a PR with a minimal test example.

While working on the test example I looked into the code and found the (probable) cause for this issue and proposed a fix for it in a second commit.

The issue seems to originate from the part of the code in UnitOfWork which calculates the weight for new dependencies in the graph based on whether or not the nullable clause on join columns is set and to which value.

In particular the part (int)empty($joinColumns['nullable']) which to me seems incorrect. With the current implementation in master the case where the nullable property on the join column is set to false (so, the relation is mandatory) yields the same weight as when the nullable property is not defined. But when the nullable property is not defined, the documention states that the default would be nullable === true.

Below, you find a simple truth table breakdown of the specific part of the code (for the possible values for $joinColumns['nullable'].

(int) empty ( $joinColumns['nullable'] )
0 false true
1 true false
1 true unset/null/etc.

I tried to keep the (in-line) fix as compact as possible. All test keep running and the added test for this issue also succeeds after applying the fix. Before applying the fix, it throws a ConstraintViolationException and tries to insert null for a mandatory foreign key.

Since I'm not completely familiar with the codebase, please look into whether this does not influence other parts of the code. If there's anything I can do to assist, let me know.

**Original Pull Request:** https://github.com/doctrine/orm/pull/6533 **State:** closed **Merged:** No --- As suggested by @lcobucci, I created a PR with a minimal test example. While working on the test example I looked into the code and found the (probable) cause for this issue and proposed a fix for it in a second commit. The issue seems to originate from the part of the code in UnitOfWork which calculates the weight for new dependencies in the graph based on whether or not the `nullable` clause on join columns is set and to which value. In particular the part `(int)empty($joinColumns['nullable'])` which to me seems incorrect. With the current implementation in `master` the case where the `nullable` property on the join column is set to false (so, the relation is mandatory) yields the same weight as when the `nullable` property is not defined. But when the `nullable` property is not defined, the documention states that the default would be `nullable === true`. Below, you find a simple truth table breakdown of the specific part of the code (for the possible values for `$joinColumns['nullable']`. | `(int)` | `empty` | `( $joinColumns['nullable'] )` | |------- |------- |------------------------------ | | 0 | false | true | | 1 | true | false | | 1 | true | unset/null/etc. | I tried to keep the (in-line) fix as compact as possible. All test keep running and the added test for this issue also succeeds after applying the fix. Before applying the fix, it throws a ConstraintViolationException and tries to insert null for a mandatory foreign key. Since I'm not completely familiar with the codebase, please look into whether this does not influence other parts of the code. If there's anything I can do to assist, let me know.
admin added the pull-request label 2026-01-22 16:06:10 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#10025