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

Avoid __toString() return null error on Doctrine Exceptions #7478

Merged

Conversation

alexander-schranz
Copy link
Member

@alexander-schranz alexander-schranz commented Jun 25, 2024

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Fixed tickets #
Related issues/PRs #
License MIT
Documentation PR sulu/sulu-docs#

What's in this PR?

Avoid __toString() on doctrine Exceptions.

Why?

If a Doctrine Exception happen doctrine tries to call $entity->__toString() method for generating the error message. But as in some cases the Tag Name is may not set it ends up in the error:

Sulu\Bundle\TagBundle\Entity\Tag::__toString(): Return value must be of type string, null returned

Most devs confused that and not looking at the Stack Trace of the error to get the real error message. To avoid this error we should always return a string if possible.

For 3.0 I would recommend to remove the magic methods so doctrine returns always the object hash, but that is a bc break at current state, so need to discussed first.

@alexander-schranz alexander-schranz added the Bug Error or unexpected behavior of already existing functionality label Jun 25, 2024
@alexander-schranz alexander-schranz changed the title Avoid __toString() on doctrine Exceptions Avoid __toString() return null error on Doctrine Exceptions Jun 25, 2024
@Prokyonn Prokyonn merged commit 10dc9e6 into sulu:2.5 Jun 25, 2024
8 checks passed
@alexander-schranz alexander-schranz deleted the enhancement/entity-too-string-error branch June 26, 2024 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Error or unexpected behavior of already existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants