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

fix(serializer): uriTemplate wrong cache usage in hal format #6313

Merged
merged 3 commits into from
Apr 17, 2024

Conversation

usu
Copy link
Contributor

@usu usu commented Apr 14, 2024

Q A
Branch? 3.2
Tickets
License MIT
Doc PR

This PR fixes a bug introduced with #5675.

For embedded subresources using the new uriTemplate property, components cache is wrongly populated and used for different entities, hence ending in wrong IRIs used in the response.

Response of features/hal/collection_uri_template.feature before fixing

Note that the IRI-link of the children subresource in the 2nd relation "asb2" is wrongly "/property_collection_iri_only_relations/1/children" instead of "/property_collection_iri_only_relations/2/children".

      {
        "_links": {
          "self": {
            "href": "/property_collection_iri_onlies/1"
          },
          "propertyCollectionIriOnlyRelation": {
            "href": "/property-collection-relations"
          },
          "iterableIri": {
            "href": "/parent/1/another-collection-operations"
          },
          "toOneRelation": {
            "href": "/parent/1/property-uri-template/one-to-ones/1"
          }
        },
        "_embedded": {
          "propertyCollectionIriOnlyRelation": [
            {
              "_links": {
                "self": {
                  "href": "/property_collection_iri_only_relations/1"
                },
                "children": {
                  "href": "/property_collection_iri_only_relations/1/children"
                }
              },
              "name": "asb1"
            },
            {
              "_links": {
                "self": {
                    "href": "/property_collection_iri_only_relations/2"
                },
                "children": {
                  "href": "/property_collection_iri_only_relations/1/children"
                }
              },
              "name": "asb2"
            }
          ],
          "iterableIri": [
            {
              "_links": {
                "self": {
                  "href": "/property_collection_iri_only_relations/9999"
                },
                "children": {
                  "href": "/property_collection_iri_only_relations/9999/children"
                }
              },
              "name": "Michel"
            }
          ],
          "toOneRelation": {
            "_links": {
              "self": {
                "href": "/parent/1/property-uri-template/one-to-ones/1"
              }
            },
            "name": "xarguš"
          }
        }
      }

Response of features/hal/collection_uri_template.feature after fixing

      {
        "_links": {
          "self": {
            "href": "/property_collection_iri_onlies/1"
          },
          "propertyCollectionIriOnlyRelation": {
            "href": "/property-collection-relations"
          },
          "iterableIri": {
            "href": "/parent/1/another-collection-operations"
          },
          "toOneRelation": {
            "href": "/parent/1/property-uri-template/one-to-ones/1"
          }
        },
        "_embedded": {
          "propertyCollectionIriOnlyRelation": [
            {
              "_links": {
                "self": {
                  "href": "/property_collection_iri_only_relations/1"
                },
                "children": {
                  "href": "/property_collection_iri_only_relations/1/children"
                }
              },
              "name": "asb1"
            },
            {
              "_links": {
                "self": {
                    "href": "/property_collection_iri_only_relations/2"
                },
                "children": {
                  "href": "/property_collection_iri_only_relations/2/children"
                }
              },
              "name": "asb2"
            }
          ],
          "iterableIri": [
            {
              "_links": {
                "self": {
                  "href": "/property_collection_iri_only_relations/9999"
                },
                "children": {
                  "href": "/property_collection_iri_only_relations/9999/children"
                }
              },
              "name": "Michel"
            }
          ],
          "toOneRelation": {
            "_links": {
              "self": {
                "href": "/parent/1/property-uri-template/one-to-ones/1"
              }
            },
            "name": "xarguš"
          }
        }
      }

Copy link
Member

@soyuka soyuka left a comment

Choose a reason for hiding this comment

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

nice thanks!

@soyuka soyuka merged commit a59fbee into api-platform:3.2 Apr 17, 2024
51 of 53 checks passed
usu added a commit to usu/ecamp3 that referenced this pull request Apr 20, 2024
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