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

Creating a index with invalid fields in the metadata does not report any error #11223

Open
stof opened this issue Feb 5, 2024 · 1 comment
Open

Comments

@stof
Copy link
Member

stof commented Feb 5, 2024

Bug Report

Q A
BC Break no
Version 2.17.4

Summary

When the fields list in an Index contains fields that don't exist in the entity, they are silently ignored without any warning, creating an index containing only the other fields.

Current behavior

How to reproduce

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity()]
#[ORM\Index(fields: ['recipient', 'created_at', 'viewed'], name: 'bad')]
#[ORM\Index(fields: ['recipient', 'createdAt', 'viewed'], name: 'good')]
class Notification
{
    /**
     * @var int
     */
    #[ORM\Id]
    #[ORM\Column(type: 'integer')]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    private $id;

    #[ORM\ManyToOne(targetEntity: User::class)]
    #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
    private User $recipient;

    #[ORM\Column(type: 'datetimetz')]
    private \DateTime $createdAt;

    #[ORM\Column(type: 'boolean')]
    private bool $viewed = false;

    // ...
}
<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity()]
class User
{
    /**
     * @var int
     */
    #[ORM\Id]
    #[ORM\Column(type: 'integer')]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    private $id;

    // ...
}

Expected behavior

Ideally, this should throw a MappingException. However, this is a BC break so it will need to wait until the next major version.

In the meantime, I see 2 possible improvements (not exclusive to each other):

  • make the SchemaValidator detect such mistake and report it as a validation error
  • add an opt-in configuration setting to turn on such stricter validation without waiting for the next major version
@stof
Copy link
Member Author

stof commented Feb 5, 2024

Note that configuring columns (expecting database column names) instead of fields (expecting names of mapped properties) is properly throwing an exception in DBAL for invalid column names. My guess is that the invalid fields are silently skipped when converting field names to column names when creating the DBAL Schema.

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

No branches or pull requests

1 participant