mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Unique validator fails on 2nd submission #6711
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 @herbyxxx on GitHub (May 10, 2021).
I have this issue in my Symfony project, however the problem seems to be related to doctrine (already created issue in symfony github for reference).
Description
I am using the Symfony UniqueEntity Validator which uses the
doctrine.orm.validator.uniqueservice with thefindBymethod.I have one Entity called
ArticleTranslationwhich has two fields calledarticle(ManyToOne to Entity Article) andlocale(language for the translation e.g. 'en' or 'de'). Those fields are unique together (only one translation per language) using@UniqueEntity(fields={"content", "locale"}). MyArticleTranslationsare persisted by usingcascade={"persist"}on theArticleclass (my article form has 1 default translation which needs to be added - so there is atleast 1 translation available).So what I did notice is, that on
devmode everything works like a charm. No issues at all. But whenever I switch toprodmode the first form submission is ok. However on the 2nd submission the@UniqueEntity(fields={"content", "locale"})fails. When you clear the cache after thatphp bin/console cache:clearit suddenly works for one time. The 2nd one fails again.I did debug the
UniqueEntityValidatorand did indeed notice some strange behavior. The data itself is always the same:However the
findBymethod (used by the validator) seems to be different at the 2nd submission. I logged my SQL queries and did notice the following:Here we notice that the WHERE is correct
WHERE t0.article_id = NULL AND t0.locale = 'de'(no result found => Unique passes)This changes on the second submission though.
with the WHERE beeing suddenly
WHERE t0.article_id = 1 AND t0.locale = 'de'(even though the Article ID is still NULL in the data).Again, after clearing the cache it works once. I really have no idea whats causing that and have a hard time to find the issue. Also as mentioned before in
devmode everything works correct (so maybe it is a cache related?)How to reproduce
Reproduce example: https://github.com/herbyxxx/issue_40832
Is there any way to fix this in doctrine? Thanks