-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[2.7][Form] #14465 introduced a new regression: empty required choice fields are not validated anymore #14607
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
Comments
Just updated to Symfony 2.7.0-BETA2 which has #14465 integrated: the problem still occurs. Sending empty form values for non nullable properties throws a SQL error instead of a form error. |
Just updated to Symfony 2.7.0: the problem still occurs. |
Hi @webmozart , I tried out the changes in #14950 , but the error still occurs, when I save a form with an empty choice for a non nullable field:
I am also unsure, if this is really a duplicate of #14583 . I'm using MySQL with Doctrine, no Postgres. |
I thought about this issue again after a while: I think the problem is, that the guessing taking place until Symfony 2.6 is broken in 2.7. In 2.6 a property of an Doctrine-Entity, that is not nullable, is considered as required by the Form. In 2.7, it's not anymore. As a workaround, I could simply add explicit My Scenario is dead simple: a) Have a Doctrine-Entity with a non nullable property, in my case a simple one-to-many-connection: /**
* @var \AppBundle\Entity\Otherentity
*
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Otherentity", inversedBy="myentity")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="other_id", referencedColumnName="id", nullable=false)
* })
*/
private $other; b) Have a Form with an Entity-type for that field: $builder
->add('other', 'entity', array(
'class' => 'AppBundle:Otherentity',
'choice_label' => 'identifyingName',
'label' => 'Other Entity',
'required' => true,
'invalid_message' => 'Please choose an Other Entity',
'placeholder' => 'Please choose',
)); c) Submit the form with no chosen Other Entity (skipping the client side validation invoked by d) Symfony 2.6: You get a Form error about the missing value for the e) Symfony 2.7: You get a database error: "SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'other_id' cannot be null" f) Add a |
Status: reviewed This should be fixed by #17760 |
Hi,
I implemented the fix from #14465 into the codebase of my Symfony 2.7.0-BETA1 based appication. Now, the non required filter form choice fields work again an do not provoke form errors, when they are empty.
But in the same time, all my required choice fields (representing non nullable database columns) do not validate anymore, when I submit them empty. Insteat I get an SQL error about the missing values for the non nullable fields. Removing the fix again resolves this.
See also my comment on the fix itself: #14465 (comment)
The text was updated successfully, but these errors were encountered: