8000 [2.7][Form] #14465 introduced a new regression: empty required choice fields are not validated anymore · Issue #14607 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[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

Closed
spackmat opened this issue May 11, 2015 · 9 comments

Comments

@spackmat
Copy link
Contributor

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)

@jakzal jakzal added the Form label May 12, 2015
@spackmat
Copy link
Contributor Author

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.

@spackmat spackmat changed the title #14465 introduces a new regression: empty required choice fields are not validated anymore 2.7.0-BETA2 / #14465 introduces a new regression: empty required choice fields are not validated anymore May 14, 2015
@spackmat
Copy link
Contributor Author

Just updated to Symfony 2.7.0: the problem still occurs.

@spackmat spackmat changed the title 2.7.0-BETA2 / #14465 introduces a new regression: empty required choice fields are not validated anymore [2.7][Form] #14465 introduced a new regression: empty required choice fields are not validated anymore May 30, 2015
@webmozart
Copy link
Contributor

Hi @spackmat, thank you for reporting this issue! This bug was fixed for Doctrine in #14950. Apart from that, it's a duplicate of #14583, hence I'm closing it.

@spackmat
Copy link
Contributor Author

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:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'otherentity_id' cannot be null

I am also unsure, if this is really a duplicate of #14583 . I'm using MySQL with Doctrine, no Postgres.

@xabbuh
Copy link
Member
xabbuh commented Jul 4, 2015

@spackmat Can you check if #15027 fixes your issue?

@spackmat
Copy link
Contributor Author
spackmat commented Jul 6, 2015

@xabbuh Hi, I inserted the changed lines from #15027. Doesn't fix the issue.

@xabbuh
Copy link
Member
xabbuh commented Jul 9, 2015

@spackmat Looks like your issue is a bit different from #14583. Can you please provide some more information about how your scenario looks like to make it possible to reproduce your issue (or even provide a fork of the Symfony Standard Edition that reproduces it)?

@xabbuh xabbuh reopened this Jul 9, 2015
@spackmat
Copy link
Contributor Author
spackmat commented Jul 9, 2015

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 NotNull Asserts inside the model definition for all of those properties, but on the other hand, IMHO this BC break should be addressed.

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 'required' => true,)

d) Symfony 2.6: You get a Form error about the missing value for the other field.

e) Symfony 2.7: You get a database error: "SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'other_id' cannot be null"

f) Add a * @Assert\NotNull() Assert to the Entity from a) and you get a form error again.

@sstok
Copy link
Contributor
sstok commented Sep 21, 2018

Status: reviewed

This should be fixed by #17760

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

No branches or pull requests

6 participants
0