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

[Serializer] fixed object normalizer for a class with cancel method #56868

Open
wants to merge 5 commits into
base: 6.4
Choose a base branch
from

Conversation

er1z
Copy link

@er1z er1z commented May 21, 2024

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
License MIT

During the debug of quite big application I found out that at unrelated edge cases a class got called cancel method. It turned out that as a part of outbox pattern, Serializer kicked in to produce failed queue message. And eventually, found out that attributes list of ObjectNormalizer contains a field cel that didn't exist anywhere.

Eventually, it turned out that for default ObjectNormalizer configuration, getters are also utilized to fetch list of attributes. But since Symfony 6.1 canners were introduced, alongside with issers and hassers. But can prefix is also applicable to a word canCel and provided PHP methods are case-insensitive, getting list of attributes caused accidental call of cancel method breaking business logic.

See attached unit test for better explanation.

@er1z er1z requested a review from dunglas as a code owner May 21, 2024 19:07
@carsonbot carsonbot added this to the 6.4 milestone May 21, 2024
@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 7.2 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@carsonbot

This comment has been minimized.

@er1z
Copy link
Author

er1z commented May 21, 2024

I can see that unit tests failures come from totally different area and the same failures repeat across different PRs. How should we proceed?

@carsonbot carsonbot changed the title fixed object normalizer for a class with cancel method [Serializer] fixed object normalizer for a class with cancel method May 22, 2024
@OskarStark
Copy link
Contributor

I can see that unit tests failures come from totally different area and the same failures repeat across different PRs. How should we proceed?

You can ignore them for now

if (str_starts_with($name, 'get') || str_starts_with($name, 'has') || str_starts_with($name, 'can')) {
if (
(str_starts_with($name, 'get') || str_starts_with($name, 'has') || str_starts_with($name, 'can'))
&& ctype_upper($name[3] ?? '')
Copy link
Member

Choose a reason for hiding this comment

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

As you said in the description methods are case insensitive in PHP, so this looks too brittle to me.

Copy link
Author

Choose a reason for hiding this comment

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

I barely see any other option that won't imply having a list of exclusions. If you have any better idea, share please.

Copy link
Author

Choose a reason for hiding this comment

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

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.

None yet

5 participants