Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DoctrineBridge] don't call EntityManager::initializeObject() with scalar values #58908

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

Merged
merged 1 commit into from
Nov 20, 2024

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Nov 18, 2024

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #58906
License MIT

Calling initializeObject() with a scalar value (e.g. the id of the associated entity) was a no-op call with Doctrine ORM 2 where no type was set with the method signature. The UnitOfWork which was called with the given argument ignored anything that was not an InternalProxy or a PersistentCollection instance.

Calls like these now break with Doctrine ORM 3 as the method's argument is typed as object now.

@carsonbot carsonbot added this to the 5.4 milestone Nov 18, 2024
@OskarStark OskarStark changed the title [DoctrineBridge] don't call EntityManager::initializeObject() with scalar values [DoctrineBridge] don't call EntityManager::initializeObject() with scalar values Nov 18, 2024
@@ -104,7 +104,7 @@ public function validate($entity, Constraint $constraint)

$criteria[$fieldName] = $fieldValue;

if (null !== $criteria[$fieldName] && $class->hasAssociation($fieldName)) {
if (null !== $criteria[$fieldName] && is_object($criteria[$fieldName]) && $class->hasAssociation($fieldName)) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (null !== $criteria[$fieldName] && is_object($criteria[$fieldName]) && $class->hasAssociation($fieldName)) {
if (\is_object($criteria[$fieldName]) && $class->hasAssociation($fieldName)) {

Calling initializeObject() with a scalar value (e.g. the id of the
associated entity) was a no-op call with Doctrine ORM 2 where no type
was set with the method signature. The UnitOfWork which was called
with the given argument ignored anything that was not an InternalProxy
or a PersistentCollection instance.

Calls like these now break with Doctrine ORM 3 as the method's argument
is typed as object now.
@nicolas-grekas
Copy link
Member

Thank you @xabbuh.

@nicolas-grekas nicolas-grekas merged commit 1d3d562 into symfony:5.4 Nov 20, 2024
4 of 5 checks passed
@xabbuh xabbuh deleted the issue-58906 branch November 20, 2024 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants