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

!!! BUGFIX: Avoid broken proxy docblocks #2568

Merged
merged 6 commits into from
Sep 29, 2021

Conversation

kdambekalns
Copy link
Member

@kdambekalns kdambekalns commented Sep 14, 2021

With PR #2533 docblocks are copied from the original class to the proxy class. This breaks when using annotations without the "standard" imports Flow and ORM. One example is the ImportedAsset domain model.

This fixes that by some changes to the proxy building.

Note, if you use property introduction via AOP, those properties must from now on use fully-qualified classnames for annoatations on them!

Fixes #2564

"use Neos\\Flow\\Annotations as Flow;\n" .
"\n" .
$this->buildClassDocumentation() .
$classCode = $this->buildClassDocumentation() .
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the actual fix…

Copy link
Member

@robertlemke robertlemke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Note, if you use property introduction via AOP, those properties must from now on use fully-qualified classnames for annoatations on them!

What happens if you don't use a fully-qualified class name? If you'll get an error during compile time and can make some sense of it to get it right, that would be fine.

@kdambekalns
Copy link
Member Author

Looks good to me.

Note, if you use property introduction via AOP, those properties must from now on use fully-qualified classnames for annoatations on them!

What happens if you don't use a fully-qualified class name? If you'll get an error during compile time and can make some sense of it to get it right, that would be fine.

You get an error like this one:

Doctrine\Common\Annotations\AnnotationException: [Semantical Error] The annotation "@ORM\Id" in property Neos\Flow\Tests\Functional\Property\Fixtures\TestValueobject::$Persistence_Object_Identifier was never imported. Did you maybe forget to add a "use" statement for this annotation?

That lacks the information about where that property actually comes from (as it's not really in TestValueObject), but the message allowed me to find the cause. YMMV.

Do you think that's sufficient?

@robertlemke
Copy link
Member

Do you think that's sufficient?

Could be better, but since it's a Doctrine exception, there's not much we can do, I guess?

@kdambekalns
Copy link
Member Author

Do you think that's sufficient?

Could be better, but since it's a Doctrine exception, there's not much we can do, I guess?

Nope. We could invest a yet unknown amount of time into detecting and/or fixing this during compile time, but… 🤷‍♂️

Copy link
Member

@albe albe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally approve, though I'm having a bit of a hard time with the "fully qualified namespace annotation required" break. Why is that needed if the original class imports the namespace? Is it really not possible to use a shortened namespace in the annotations?

@@ -70,8 +70,8 @@ public function isEntityOrValueObject()

/**
* @var string
* @ORM\Id
* @ORM\Column(length=40)
* @Doctrine\ORM\Mapping\Id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, but doesn't the "manual" import in lines 14+15 suffice to have the short named annotation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because that docblock (of the aspect class) is not copied into the class the property is introduced into…

Copy link
Member

@albe albe Sep 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. Could we possibly monkey-patch https://github.com/neos/flow-development-collection/blob/master/Neos.Flow/Classes/Aop/PropertyIntroduction.php#L83 for a b/c fix to this? I guess it's still hard to resolve the string class name without parsing the use statements of the Aspect class... maybe at least resolve @ORM\ and @Flow\ there to somewhat lower breakyness?

Edit: Did it even ever work for anything besides ORM and Flow? Looking at https://github.com/neos/flow-development-collection/pull/2568/files#diff-cd6bee66fb3ab0580a3e15bfdfa76d82c2c5983e69ec8a5d3211790c7d6c950bL47-L49 I think no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It did, because we did not copy the docblock, but re-rendered any annotations, making them fully qualified. As can be seen in the example with the Entity annotation in #2564.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About the breakiness… TBH I have no clue how much property introduction is actually used and if those few places cannot be fixed faster, than it would take us to come up with a fix that doesn't come with additional (potential) bugs…

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay - still, wdyt about making Flow and ORM work by hardcoding the FQCN resolution for those? Whenever you want to inject a property, it's most likely a DB field or some Flow injected property.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would reduce the pain. But for the record, in random projects I randomly don't use the general Flow\Annotations import, but rather import @Inject() (for example) directly, because Phpstorm let's me do that very easily. These cases would still break.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would reduce the pain. But for the record, in random projects I randomly don't use the general Flow\Annotations import, but rather import @Inject() (for example) directly, because Phpstorm let's me do that very easily. These cases would still break.

uh, would not break, right? Because I imported it and I'm not using the FQCN.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would break, because your import in the aspect class' docblock is never copied to the class you introduce a property to. This is only about annotations on introduced properties

We can of course expand @ORM\ and @Flow, feel free to improve this (I won't have time today)…

Copy link
Member

@mficzel mficzel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot say much about the code but can confirm that the issues are solved.

@kdambekalns kdambekalns merged commit a2759ec into neos:7.2 Sep 29, 2021
@kdambekalns kdambekalns deleted the bugfix/proxy-docblock-annotations branch September 29, 2021 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants