Skip to content

Conversation

@rvanlaak
Copy link
Contributor

@rvanlaak rvanlaak commented Jan 5, 2026

Did receive this exception in an environment out of my control, and message was not helping sufficiently with root cause analysis.

Q A
Branch? main
Tickets N/A
License MIT
Doc PR N/A


if (!\is_object($attributeValue) && null !== $attributeValue) {
throw new UnexpectedValueException('Unexpected non-object value for to-one relation.');
throw new UnexpectedValueException('Unexpected non-object value for to-one relation on class `'.$object::class.'` for attribute `'.$attribute.'`.');
Copy link
Member

Choose a reason for hiding this comment

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

isn't this exposing too much information?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By which you're referring to security related concerns? Disabling showing errors in prod environments imo is a userland concern, implying that exception messages can't be extensive and clear enough. The current message does not really help much in solving the issue.

@rvanlaak
Copy link
Contributor Author

rvanlaak commented Jan 5, 2026

The actual root cause of the issue was an entity having a is... method on a relationship, which potentially could be an issue on it's own?

#[ApiResource]
class Foo {

    private Bar $bar;

	public function isBar(): bool
	{
		// ...
	}
}

with the change of this PR would lead to

In AbstractItemNormalizer.php line 946:
                                                                               
  Unexpected non-object value for to-one relation on class `App\Domain\Foo` for attribute `bar`.                                             
                                                                               

@soyuka
Copy link
Member

soyuka commented Jan 5, 2026

not sure, probably it should be hasBar ? I didn't make up the property accessor naming rules :p. How did you fix this in the end?
Could you target 4.2 for this patch?

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

Successfully merging this pull request may close these issues.

2 participants