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

Closed
opened 2026-01-22 15:45:33 +01:00 by admin · 9 comments
Owner

Originally created by @verfriemelt-dot-org on GitHub (May 8, 2023).

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 ✌️

Originally created by @verfriemelt-dot-org on GitHub (May 8, 2023). <!-- Before reporting a BC break, please consult the upgrading document to make sure it's not an expected change: https://github.com/doctrine/orm/blob/2.9.x/UPGRADE.md --> ### 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: ```php #[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 :v:
admin closed this issue 2026-01-22 15:45:33 +01:00
Author
Owner

@verfriemelt-dot-org commented on GitHub (May 8, 2023):

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

image

@verfriemelt-dot-org commented on GitHub (May 8, 2023): mhmm, maybe thats a bit misleading, not sure. here is a stacktrace when debugging that issue: ![image](https://user-images.githubusercontent.com/1136869/236903587-7432a0f9-8d28-4963-bf04-c58a521c4475.png)
Author
Owner

@greg0ire commented on GitHub (May 8, 2023):

🤔 where does that point_target come from?

@greg0ire commented on GitHub (May 8, 2023): :thinking: where does that `point_target` come from?
Author
Owner

@greg0ire commented on GitHub (May 8, 2023):

https://github.com/doctrine/orm/pull/10671 looks like it could cause the issue, Cc @BoShurik

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

@greg0ire commented on GitHub (May 8, 2023): https://github.com/doctrine/orm/pull/10671 looks like it could cause the issue, Cc @BoShurik @verfriemelt-dot-org can you try removing the lines introduced in that PR?
Author
Owner

@verfriemelt-dot-org commented on GitHub (May 8, 2023):

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 commented on GitHub (May 8, 2023): 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](https://user-images.githubusercontent.com/1136869/236927435-6963ebf6-97fb-4284-bc9d-df04c4069dae.png)
Author
Owner

@verfriemelt-dot-org commented on GitHub (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 :)

@verfriemelt-dot-org commented on GitHub (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? :thinking: 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? :thinking: thanks for your help anyways :)
Author
Owner

@greg0ire commented on GitHub (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 commented on GitHub (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?
Author
Owner

@verfriemelt-dot-org commented on GitHub (May 9, 2023):

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]
@verfriemelt-dot-org commented on GitHub (May 9, 2023): 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] ```
Author
Owner

@endelwar commented on GitHub (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 9bc6f5b4ac/lib/Doctrine/ORM/Mapping/Driver/AttributeDriver.php (L694) , coming from 9bc6f5b4ac/lib/Doctrine/ORM/Mapping/Driver/AttributeDriver.php (L442)

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;
@endelwar commented on GitHub (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) ```php #[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 https://github.com/doctrine/orm/blob/9bc6f5b4ac6f1e7d4248b2efbd01a748782075bc/lib/Doctrine/ORM/Mapping/Driver/AttributeDriver.php#L694 , coming from https://github.com/doctrine/orm/blob/9bc6f5b4ac6f1e7d4248b2efbd01a748782075bc/lib/Doctrine/ORM/Mapping/Driver/AttributeDriver.php#L442 If I change the `joinColumn` and `inverseJoinColumns` declaration 2.15.1 it works as expected: ```php #[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; ```
Author
Owner

@greg0ire commented on GitHub (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.

@greg0ire commented on GitHub (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 in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7147