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

Conversion of object query parameters to their identifiers is inconsistent #6209

Open
stof opened this issue Jan 3, 2017 · 6 comments
Open
Labels

Comments

@stof
Copy link
Member

stof commented Jan 3, 2017

The detection of whether the object is an entity uses $this->_em->getMetadataFactory()->hasMetadataFor(ClassUtils::getClass($value)). But hasMetadataFor checks whether the factory has loaded metadata for the class. So the behavior depends on what happened previously in the request (and can change between a dev environment and the prod as the prod is more likely to use a cache for the DQL parsing logic, which is one of the place which could trigger the loading of metadata when being executed).

I suggest switching to using ! isTransient() instead (potentially keeping the check for loaded metadata first for performance reasons as isTransient does not check the loaded metadata to short-circuit drivers).
what do you think about it ?

@Ocramius
Copy link
Member

Ocramius commented Jan 3, 2017

I think we should modify hasMetadataFor() so that it actually does an internal lookup, and fails silently if the requested class is not mapped. The fact that hasMetadataFor() always checks for current in-memory state is a big annoyance, and it caused a lot of bugs in the past as well.

@Ocramius Ocramius added the Bug label Jan 3, 2017
@stof
Copy link
Member Author

stof commented Jan 3, 2017

you mean making hasMetadataFor the equivalent of ! isTransient for the returned value ? This would be fine with me, but it could be considered a BC break

@stof
Copy link
Member Author

stof commented Jan 3, 2017

Btw, this would require changing the interface in doctrine/common too, because this is the documented behavior: https://github.com/doctrine/common/blob/v2.7.1/lib/Doctrine/Common/Persistence/Mapping/ClassMetadataFactory.php#L54

so I'd rather not change it now

@Ocramius
Copy link
Member

Ocramius commented Jan 3, 2017

@stof I can find bugs for basically every usage of hasMetadataFor, so I think making it an alias (and keeping a map of the transient classes internally, for performance) would be a massive improvement.

About BC breaks, it would need a lookup (on github) of who uses that method, and for which purposes.

@Ocramius
Copy link
Member

Ocramius commented Jan 3, 2017

@stof yeah, the interface change would indeed be a breakage, nice spotting :-\

@InputOutput
Copy link

I think I just encountered this bug in the wild, using an Entity as parameter in a where condition in DQL without specifying the specific property to use (in this case ID). Worked fine in dev mode, broke after cache warmup in production.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants