DDC-1740: EntityRepository::find throws "The identifier id is missing for a query" when argument with null value is passed (backward compatibility break) #2188

Closed
opened 2026-01-22 13:43:45 +01:00 by admin · 6 comments
Owner

Originally created by @doctrinebot on GitHub (Mar 30, 2012).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user disago:

Bug was introduced in commit https://github.com/doctrine/doctrine2/commit/619a31913a4f5952248a0b909a25c2020619c29f.

If a variable with null value is passed to a repository find() method the exception is thrown because isset() is used instead of array_key_exists() to check for a valid identifier key (and isset returns false when the variable has null). This introduces a BC break in current scenarios that expected that doing a find($variableWithNullValue) should return null instead of raising an exception.

        $sortedId = array();
        foreach ($this->_class->identifier as $identifier) {
            if (!isset($id[$identifier])) {
                throw ORMException::missingIdentifierField($this->_class->name, $identifier);
            }
            $sortedId[$identifier] = $id[$identifier];
        }

Should be:

        $sortedId = array();
        foreach ($this->_class->identifier as $identifier) {
            if ( ! array*key*exists($identifier, $id) ) {
                throw ORMException::missingIdentifierField($this->_class->name, $identifier);
            }
            $sortedId[$identifier] = $id[$identifier];
        }
Originally created by @doctrinebot on GitHub (Mar 30, 2012). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user disago: Bug was introduced in commit [https://github.com/doctrine/doctrine2/commit/619a31913a4f5952248a0b909a25c2020619c29f](Message). If a variable with _null_ value is passed to a repository _find()_ method the exception is thrown because _isset()_ is used instead of _array_key_exists()_ to check for a valid identifier key (and isset returns _false_ when the variable has _null_). This introduces a BC break in current scenarios that expected that doing a _find($variableWithNullValue)_ should return _null_ instead of raising an exception. ``` $sortedId = array(); foreach ($this->_class->identifier as $identifier) { if (!isset($id[$identifier])) { throw ORMException::missingIdentifierField($this->_class->name, $identifier); } $sortedId[$identifier] = $id[$identifier]; } ``` Should be: ``` $sortedId = array(); foreach ($this->_class->identifier as $identifier) { if ( ! array*key*exists($identifier, $id) ) { throw ORMException::missingIdentifierField($this->_class->name, $identifier); } $sortedId[$identifier] = $id[$identifier]; } ```
admin added the Bug label 2026-01-22 13:43:45 +01:00
admin closed this issue 2026-01-22 13:43:46 +01:00
Author
Owner

@doctrinebot commented on GitHub (Mar 30, 2012):

Comment created by disago:

Patch attached

@doctrinebot commented on GitHub (Mar 30, 2012): Comment created by disago: Patch attached
Author
Owner

@doctrinebot commented on GitHub (Mar 30, 2012):

Comment created by @beberlei:

Its a BC break, but the previous behavior is invalid. The method expects an identifier, which by definition cannot be null.

@doctrinebot commented on GitHub (Mar 30, 2012): Comment created by @beberlei: Its a BC break, but the previous behavior is invalid. The method expects an identifier, which by definition cannot be null.
Author
Owner

@doctrinebot commented on GitHub (Mar 30, 2012):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Mar 30, 2012): Issue was closed with resolution "Invalid"
Author
Owner

@doctrinebot commented on GitHub (Dec 13, 2015):

Imported 1 attachments from Jira into https://gist.github.com/20b09dd46a7fcb12a4bf

@doctrinebot commented on GitHub (Dec 13, 2015): Imported 1 attachments from Jira into https://gist.github.com/20b09dd46a7fcb12a4bf - [11174_DDC-1740.patch](https://gist.github.com/20b09dd46a7fcb12a4bf#file-11174_DDC-1740-patch)
Author
Owner

@andho commented on GitHub (Jul 8, 2016):

"Argument 1 passed to find should not be null." would be a more appropriate exception.

@andho commented on GitHub (Jul 8, 2016): "Argument 1 passed to `find` should not be null." would be a more appropriate exception.
Author
Owner

@Ocramius commented on GitHub (Jul 8, 2016):

find() allows an array of values to be passed in. If any of the identifier fields passed to find() is null, then it should fail. missingIdentifierField is what is closest (semantically) to this behavior. Feel free to send a patch with an improved error message though.

@Ocramius commented on GitHub (Jul 8, 2016): `find()` allows an array of values to be passed in. If any of the identifier fields passed to `find()` is `null`, then it should fail. `missingIdentifierField` is what is closest (semantically) to this behavior. Feel free to send a patch with an improved error message though.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2188