Skip to content

Fix scalar message header conversion to nullable enums - #689

Merged
dgafka merged 2 commits into
ecotoneframework:mainfrom
lifinsky:bug/nullable-enum-header-conversion
Jul 28, 2026
Merged

Fix scalar message header conversion to nullable enums#689
dgafka merged 2 commits into
ecotoneframework:mainfrom
lifinsky:bug/nullable-enum-header-conversion

Conversation

@lifinsky

@lifinsky lifinsky commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix scalar message header conversion for nullable enum handler parameters.

Problem

When a message handler declares a nullable enum header parameter:

#[Header('deliveryMethod')]
?DeliveryMethod $deliveryMethod = null

Ecotone represents the target type as the DeliveryMethod|null union.

ScalarToEnumConverter correctly recognizes the target as an enum-compatible type, but then passes the complete union type string to ReflectionEnum. This results in the following error for a non-null scalar header value:

Class "DeliveryMethod|null" does not exist

A missing header or a header with a null value is not affected because scalar-to-enum conversion is not required in that case.

Fix

When the target is a union type, remove null before creating ReflectionEnum and converting the scalar value to the enum case.

Commit Structure

  1. Add a regression test that reproduces the failure without the fix.
  2. Add the minimal fix to ScalarToEnumConverter.

Verification

Before the fix, the regression test fails with:

Class "DeliveryMethod|null" does not exist

After the fix:

OK (1 test, 1 assertion)

The existing Core test suite also passes.

Pull Request Contribution Terms

  • I have read and agree to the contribution terms outlined in CONTRIBUTING.

@lifinsky

Copy link
Copy Markdown
Contributor Author

@dgafka Hi, I need your help :)

@lifinsky
lifinsky force-pushed the bug/nullable-enum-header-conversion branch from 9124bba to b22a1e4 Compare July 23, 2026 13:46
@lifinsky
lifinsky force-pushed the bug/nullable-enum-header-conversion branch from b22a1e4 to d93deed Compare July 23, 2026 14:16
@lifinsky lifinsky changed the title Reproduce scalar header conversion failure for nullable enums Fix scalar message header conversion to nullable enums Jul 23, 2026

@dgafka dgafka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Make sense, thanks for the fix :)

@dgafka
dgafka merged commit 933cc3b into ecotoneframework:main Jul 28, 2026
9 checks passed
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