Throw 404 EntityNotFoundException when query entity cannot be resolved#30
Merged
Conversation
Previously, ValueAssigner::assignEntityValueFromRepository() called the configured accessor on the repository lookup result before checking it for null. An unresolvable required query parameter (e.g. an unknown citySlug) therefore crashed with "Call to a member function on null", surfacing as a 500 Internal Server Error in consuming applications. Without an accessor the null lookup result silently skipped the filter, returning the unfiltered entity list instead — equally wrong. Now both cases throw the new EntityNotFoundException, which implements Symfony's HttpExceptionInterface with status 404, so consuming applications render a proper Not Found response without any changes. Co-Authored-By: Claude Fable 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ValueAssigner::assignEntityValueFromRepository(): the configuredaccessorwas invoked on the repository lookup result before the null check. AnyRequiredQueryParametervalue that could not be resolved (e.g.GET /api/ride?citySlug=unknown-cityon criticalmass.in) crashed with "Call to a member function getCity() on null" and surfaced as 500 Internal Server Error.EntityNotFoundException(extendsDataQueryException, implements Symfony'sHttpExceptionInterfacewith status 404). Consuming applications render a proper 404 Not Found automatically, no application-side changes required.find, custom repository method, accessor — found, not found, accessor returns null) plus reusable fixtures (SimpleEntityQuery,SimpleEntityContainer,SimpleEntityContainerRepository).Design notes
EntityNotFoundExceptionimplementsHttpExceptionInterfaceinstead of staying HTTP-agnostic so that Symfony's exception listener maps it to 404 out of the box. The bundle already targets Symfony applications (symfony/framework-bundleis a hard requirement) and the parameter resolution is inherently request-driven, mirroring how Doctrine's param converters throwNotFoundHttpException.Test Plan
composer run tests— 361 tests, 534 assertions, green (5 new tests)composer run phpstan— no errors (verified with platform PHP 8.3 / Symfony 7, matching CI)GET https://criticalmass.in/api/ride?citySlug=unknownreturns 404 instead of 500🤖 Generated with Claude Code