Skip to content

Fix: Passing nor an unknown iri nor an array in an embedded relation throws an error#1547

Merged
dunglas merged 1 commit into
api-platform:2.0from
jdeniau:fix-relationWithWrongIri
Dec 6, 2017
Merged

Fix: Passing nor an unknown iri nor an array in an embedded relation throws an error#1547
dunglas merged 1 commit into
api-platform:2.0from
jdeniau:fix-relationWithWrongIri

Conversation

@jdeniau

@jdeniau jdeniau commented Dec 6, 2017

Copy link
Copy Markdown
Contributor
Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets ~
License MIT
Doc PR ~

POST /relation_embedders
with body:

{
  "related": "foo"
}

will throw an error:
Type error: Argument 2 passed to ApiPlatform\Core\Metadata\Property\Factory\CachedPropertyMetadataFactory::create() must be of the type string, integer given, called in src/Serializer/AbstractItemNormalizer.php on line 163 (Behat\Testwork\Call\Exception\FatalThrowableError)

This is because "related" is marked as a "writable link"

@jdeniau jdeniau force-pushed the fix-relationWithWrongIri branch from 526e0ba to 0b96a0c Compare December 6, 2017 06:28
@backbone87

backbone87 commented Dec 6, 2017

Copy link
Copy Markdown

foo can be a valid IRI

https://json-ld.org/spec/latest/json-ld/#base-iri

@jdeniau jdeniau force-pushed the fix-relationWithWrongIri branch from 0b96a0c to 1f4c01e Compare December 6, 2017 06:33
@jdeniau jdeniau changed the base branch from master to 2.0 December 6, 2017 06:33
@jdeniau

jdeniau commented Dec 6, 2017

Copy link
Copy Markdown
Contributor Author

It can be a valid IRI but it's not known by our application. I rewrited the title to be more comprehensible

@jdeniau jdeniau changed the title Fix: Passing nor an iri or a array in an embedded relation throws an error Fix: Passing nor an unknown iri nor an array in an embedded relation throws an error Dec 6, 2017
@jdeniau

jdeniau commented Dec 6, 2017

Copy link
Copy Markdown
Contributor Author

Well tests are passing except the symfony deprecated (because I am based on 2.0).

I do not know why travis does not report status: https://travis-ci.org/api-platform/core/builds/312259197

}

if (!$this->resourceClassResolver->isResourceClass($className) || $propertyMetadata->isWritableLink()) {
$isResourceClass = $this->resourceClassResolver->isResourceClass($className);

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.

If I understand correctly, the variables are useless, can you just add the is_array check without introducing new vars?

@jdeniau

jdeniau commented Dec 6, 2017 via email

Copy link
Copy Markdown
Contributor Author

@dunglas

dunglas commented Dec 6, 2017

Copy link
Copy Markdown
Member

@jdeniau can you remove them please, we try to make as few assignation as possible (especially in the normalizers).

@jdeniau jdeniau force-pushed the fix-relationWithWrongIri branch from 1f4c01e to 4188f53 Compare December 6, 2017 09:47
@jdeniau

jdeniau commented Dec 6, 2017

Copy link
Copy Markdown
Contributor Author

done

@dunglas dunglas merged commit 2fbf647 into api-platform:2.0 Dec 6, 2017
@dunglas

dunglas commented Dec 6, 2017

Copy link
Copy Markdown
Member

Thanks @jdeniau!

@jdeniau jdeniau deleted the fix-relationWithWrongIri branch December 6, 2017 10:29
hoangnd25 pushed a commit to hoangnd25/core that referenced this pull request Feb 23, 2018
…ngIri

Fix: Passing nor an unknown iri nor an array in an embedded relation throws an error
dunglas added a commit to dunglas/core that referenced this pull request Mar 9, 2018
dunglas added a commit that referenced this pull request Mar 9, 2018
Fix a BC break introduced by #1547
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.

3 participants