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

Fix using enums with the QueryBuilder #10058

Merged
merged 1 commit into from Sep 23, 2022

Conversation

HypeMC
Copy link
Contributor

@HypeMC HypeMC commented Sep 22, 2022

Fixes #10057.

After upgrading to version 2.13.2 I started getting the following error:

App\Enum\TestEnum::from(): Argument #1 ($value) must be of type string, App\Enum\TestEnum given

It happens when an enum is used with the QueryBuilder, eg:

$testRepository
    ->createQueryBuilder('t')
    ->where('t.enum = :type')
    ->setParameter('type', TestEnum::Foo)
    ->getQuery()->getResult()
;

Caused by #10041.

Since my knowledge of the ORM code base is limited I'm not sure if this is the best place to fix the bug, so any suggestions are appreciated.

@greg0ire
Copy link
Member

Cc @michnovka

@greg0ire greg0ire added the Bug label Sep 22, 2022
@michnovka
Copy link
Contributor

michnovka commented Sep 23, 2022 via email

@michnovka
Copy link
Contributor

This is a good fix, and I also believe we now cover all enum hydrator test cases, so no such regression bugs should occur in the future. Thanks @HypeMC

@greg0ire greg0ire merged commit 2e7c2bb into doctrine:2.13.x Sep 23, 2022
@greg0ire greg0ire added this to the 2.13.3 milestone Sep 23, 2022
@greg0ire
Copy link
Member

Thanks @HypeMC !

@HypeMC HypeMC deleted the enum-with-query-builder-fix branch September 24, 2022 00:53
@tip2tail
Copy link

Hello, when can we expect this to be released?

@greg0ire
Copy link
Member

Soon ™️

I think we should try to batch #10059 in the same release, and it looks ready.

@trsteel88
Copy link
Contributor

trsteel88 commented Oct 10, 2022

There is a further issue here. hasChangedField is always returning true for an enum regardless of whether it actually changed.

When using hasChangedField('status') it shows it as changed when it hasn't.

@trsteel88
Copy link
Contributor

Just further to my last comment, when dumping the old/new values. The difference is that getOldValue() gives the enum object whereas getNewValue() return the enum's value. My guess is the comparison is failing because these should both be the enum object?

@michnovka
Copy link
Contributor

@trsteel88 there is a separate PR for this issue #10074

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.

2.13.2 breaks all queries with object hydration for entities using Enum fields
8 participants