Skip to content

'Cannot access uninitialized non-nullable property' on symfony/var-exporter 6.3.9 #52839

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
stephanvierkant opened this issue Nov 30, 2023 · 12 comments

Comments

@stephanvierkant
Copy link
Contributor

Symfony version(s) affected

6.3.9, 6.4.0

Description

As of Symfony/var-exporter 6.3.9 I've got this error message on multiple places in my application:

Cannot access uninitialized non-nullable property App\Entity\User::$notifications by reference

It happens when I get an Organization from Doctrine.

My entity:

#[\ApiPlatform\Metadata\ApiResource(
    // ...
)]
#[\Doctrine\ORM\Mapping\Entity(UserRepository::class)]
class User
{
    #[ManyToOne(Organisation::class, cascade: ['persist'], inversedBy: 'users')]
    #[Gedmo\Versioned]
    private ?Organisation $organisation = null;

    #[OneToMany('user', targetEntity: \App\Entity\User\Notification::class)]
    private Collection $notifications;
    public function __construct()
    {
        $this->notifications = new ArrayCollection();
    }
}

How to reproduce

I'll create a reproducer if necessary, but before I do I'd like to hear some feedback. Maybe it's a simple mistake I've made, or someone has some suggestions how to create a reproducer.

Possible Solution

No response

Additional Context

No response

@nicolas-grekas
Copy link
Member

This might have been solved by #52797. Can you please give it a try? (you might need to clear the cache explicitly before trying again)

@stephanvierkant
Copy link
Contributor Author

It has landed in 6.4.0 hasn't it? If so: nope, that didn't fix it. And yes, I've cleared the cache.

@nicolas-grekas
Copy link
Member

In 6.4-dev

@stephanvierkant
Copy link
Contributor Author

@nicolas-grekas No, it didn't fix it.

@nicolas-grekas
Copy link
Member

Could you please create a small app I could clone that reproduces the issue?

@stephanvierkant
Copy link
Contributor Author

I'll do! I've already found out that #52762 caused this issue.

@xabbuh
Copy link
Member

xabbuh commented Dec 1, 2023

Can you double-check and confirm that neither 6.3.10 nor 6.4.1 did fix this issue?

@xabbuh
Copy link
Member

xabbuh commented Dec 6, 2023

@stephanvierkant Did you have the chance to test it again?

@stephanvierkant
Copy link
Contributor Author

Yes, but it didn't help.

(sorry, didn't find the time to create a reproduceer yet)

@xabbuh
Copy link
Member

xabbuh commented Dec 15, 2023

Let's close here for now. We can still consider to reopen once we are able to reproduce it.

@xabbuh xabbuh closed this as not planned Won't fix, can't repro, duplicate, stale Dec 15, 2023
@stephanvierkant
Copy link
Contributor Author

stephanvierkant commented Dec 20, 2023

I have tried to create a reproducer, but unfortunately, I was not successful. In a simple application, it works fine, so apparently there is something specific in my application that I have not been able to locate yet.

I unfortunately cannot provide access to my application, but if someone is willing to help, I can temporarily share the code. Perhaps someone can assist in identifying where the problem might be.

I'm using magic setters/getters in my entities, maybe this can cause the issue? And the relations (user->notifications) are LAZY.

@stephanvierkant
Copy link
Contributor Author

@xabbuh I think I've found it. I'll try to create a reproducer, but meanwhile let me give a simplified example of my use case:

I've got an Item, Property and ItemProperty entity. So I've got a Car (item), colour/size/whatever (property) and a relationship: red car. Using magic method __set I'm calling $car->colour = 'red'. That __set method looks up property to see if it has to change to colour ($property->setValue('red')) or create a new ItemProperty.

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

4 participants