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

2.15.1 generated warnings in AttributeDriver::joinColumnToArray() #10690

Closed
verfriemelt-dot-org opened this issue May 8, 2023 · 9 comments
Closed

Comments

@verfriemelt-dot-org
Copy link

BC Break Report

Q A
BC Break yes
Version 2.15.1 (no warnings in 2.15.0)

Summary

this change: https://github.com/doctrine/orm/pull/10671/files#diff-c058a8444ffba22cecd48a76b9577187ef8eba003369d9b8d94313b4325d1b76
results in warnings due to seemling a wrong data type beeing passed?

Warning: Attempt to read property "name" on string in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/AttributeDriver.php on line 694
Warning: Attempt to read property "unique" on string in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/AttributeDriver.php on line 695
Warning: Attempt to read property "nullable" on string in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/AttributeDriver.php on line 696
Warning: Attempt to read property "onDelete" on string in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/AttributeDriver.php on line 697
Warning: Attempt to read property "columnDefinition" on string in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/AttributeDriver.php on line 698
Warning: Attempt to read property "referencedColumnName" on string in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/AttributeDriver.php on line 699
Warning: Attempt to read property "options" on string in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/AttributeDriver.php on line 702

Previous behavior

no warnings

Current behavior

warnings described above

How to reproduce

the entity which triggers:

#[ORM\Table(name: 'point_import_service')]
#[ORM\Entity(repositoryClass: PointImportServiceRepository::class)]
class PointImportService
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(name: 'id', type: Types::INTEGER)]
    private int $id;

    /** @var class-string */
    #[ORM\Column(name: 'class', type: Types::TEXT, nullable: false)]
    private string $class;

    #[ORM\ManyToOne(targetEntity: Provider::class, inversedBy: 'apps')]
    #[ORM\JoinColumn(name: 'provider_code', referencedColumnName: 'code', nullable: false)]
    private Provider $provider;

is that entity somewhat misconfigured? or is that a bug?

thanks for your effort ✌️

@verfriemelt-dot-org
Copy link
Author

mhmm, maybe thats a bit misleading, not sure.
here is a stacktrace when debugging that issue:

image

@greg0ire
Copy link
Member

greg0ire commented May 8, 2023

🤔 where does that point_target come from?

@greg0ire
Copy link
Member

greg0ire commented May 8, 2023

#10671 looks like it could cause the issue, Cc @BoShurik

@verfriemelt-dot-org can you try removing the lines introduced in that PR?

@verfriemelt-dot-org
Copy link
Author

yes, can confirm.
to be exact this part causes the issue:

                    foreach ($joinTableAttribute->inverseJoinColumns as $joinColumn) {
                        $joinTable['inverseJoinColumns'][] = $this->joinColumnToArray($joinColumn);
                    }

seems we have assinged $joinTableAttribute->inverseJoinColumns as an instance of inverseJoinColumn instead of inverseJoinColumn[] and while iterating over that object, we get the first attribute which is name:

image

@verfriemelt-dot-org
Copy link
Author

verfriemelt-dot-org commented May 8, 2023

when checking where this is coming from, it might be this wrongly defined entity?

    #[ORM\ManyToMany(targetEntity: Point::class, cascade: ['persist'])]
    #[ORM\JoinTable(name: 'point_has_points',  joinColumns: new ORM\JoinColumn(name: 'point_source'), inverseJoinColumns: new ORM\InverseJoinColumn(name: 'point_target'))]
    private Collection $childPoints;

i guess

    #[ORM\ManyToMany(targetEntity: Point::class, cascade: ['persist'])]
    #[ORM\JoinTable(name: 'point_has_points',  joinColumns: [new ORM\JoinColumn(name: 'point_source')], inverseJoinColumns: [new ORM\InverseJoinColumn(name: 'point_target')])]
    private Collection $childPoints;

would be correct? 🤔

well yes in fact, that works with the new version then.
okay, so i had an issue with my setup. might be a good idea to add a warning/exception? 🤔

thanks for your help anyways :)

@greg0ire
Copy link
Member

greg0ire commented May 8, 2023

okay, so i had an issue with my setup. might be a good idea to add a warning/exception? thinking

Maybe yes… did the schema validation Symfony command not warn about the issue?

@greg0ire greg0ire closed this as completed May 8, 2023
@verfriemelt-dot-org
Copy link
Author

nope:

$ bin/console doctrine:schema:validate

Mapping
-------


 [OK] The mapping files are correct.

and with the 2.15.1 i got the same issue like we discussed here:

Mapping
-------


In AttributeDriver.php line 694:

  Warning: Attempt to read property "name" on string


doctrine:schema:validate [--em EM] [--skip-mapping] [--skip-sync]

@endelwar
Copy link

endelwar commented May 9, 2023

Has the syntax below been deprecated and removed? I don't get any warning with both 2.14.3 and 2.15.0 (everything is working as expected)

#[ORM\ManyToMany(targetEntity: Product::class)]
#[ORM\JoinTable(name: 'news_product',
    schema: 'a_different_db',
    joinColumns: [
        ORM\JoinColumn::class => ['name' => 'news_id', 'referencedColumnName' => 'id'],
    ],
    inverseJoinColumns: [
        ORM\JoinColumn::class => ['name' => 'product_id', 'referencedColumnName' => 'id'],
    ]
)]
private Collection $products;

Upgrading to 2.15.1 my Symfony 5.4 project throws an ErrorException: "Warning: Attempt to read property "name" on array" here

'name' => $joinColumn->name,
, coming from
$joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumn);

If I change the joinColumn and inverseJoinColumns declaration 2.15.1 it works as expected:

#[ORM\ManyToMany(targetEntity: Product::class)]
#[ORM\JoinTable(name: 'news_product',
    schema: 'a_different_db',
    joinColumns: [
        new ORM\JoinColumn(name: 'news_id', referencedColumnName: 'id'),
    ],
    inverseJoinColumns: [
        new ORM\JoinColumn(name: 'product_id', referencedColumnName: 'id'),
    ]
)]
private Collection $products;

@greg0ire
Copy link
Member

greg0ire commented May 9, 2023

As far as I understood that's because these join column declarations did not do anything in previous versions. Please let me know if I am wrong.

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

3 participants