symfony / symfony/maker-bundle

make:entity setter for non nullable fields must allow null values to allow validating

Open
#273 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug
Dominant language
PHP
Stars
3.4k
Forks
427
Avg merge
2d 22h
Merged PRs (30d)
20

Description

This is closely related to #198.

As @javiereguiluz comments, all setters - even for nullable fields - must allow null values to be passed in order for the validation to work. At the moment:

   /**
     * @ORM\Column(type="integer", nullable=false)
     * @Assert\NotNull()
     */
    private $adpointPublicationId;

generates:

    public function setAdpointPublicationId(int $adpointPublicationId): self
    {
        $this->adpointPublicationId = $adpointPublicationId;

        return $this;
    }

so when null values passed through a form, we get the following error before validation is done.

Argument 1 passed to App\Entity\Product::setAdpointSectionGroupId() must be of the type integer, null given, called in .../backend/vendor/symfony/property-access/PropertyAccessor.php on line 527
Exception

Thanks, Hannes

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the make:entity command's setter generation and review the behavior described in related issue #198. Reproduce the example with a non-nullable field receiving null through a form; done means the generated setter accepts null so validation can run before the type error.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.