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

Bugfix: Ignore empty relationships on App Store Connect resources #401

Merged
merged 4 commits into from
Apr 24, 2024

Conversation

priitlatt
Copy link
Contributor

@priitlatt priitlatt commented Apr 23, 2024

It is possible that App Store Connect API returns resources with empty relationships. For example List Apps endpoint can respond with a response where an app has ciProduct relationship defined as {} instead of null even though the schema suggests that relationships should always have at least links attribute defined.

Such a response breaks data deserialization.

Example with stacktrace
def test_empty_relationship():
>       App(
            {
                "type": "apps",
                "id": "...",
                "links": {...},
                "attributes": {...},
                "relationships": {
                    ...,
                    "ciProduct": {},  # <-- empty relationship from App Store Connect API response!
                },
            },
        )

test_app_resource.py:18: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../../src/codemagic/apple/resources/resource.py:241: in __init__
    self.relationships = self._create_relationships(api_response)
../../../src/codemagic/apple/resources/resource.py:233: in _create_relationships
    return cls.Relationships(**defined_fields)
<string>:18: in __init__
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = App.Relationships(appInfos=Relationship(links=<codemagic.apple.resources.resource.Links object at 0x106058680>, data=N..., perfPowerMetrics={'links': {'related': 'https://api.appstoreconnect.apple.com/v1/apps/1481211155/perfPowerMetrics'}})

    def __post_init__(self):
        for field in self.__dict__:
            value = getattr(self, field)
            if not isinstance(value, (Relationship, type(None))):
>               setattr(self, field, Relationship(**value))
E               TypeError: Relationship.__init__() missing 1 required positional argument: 'links'

../../../src/codemagic/apple/resources/resource.py:215: TypeError

Handle empty relationships by just discarding them.

@priitlatt priitlatt added the bug Something isn't working label Apr 23, 2024
@priitlatt priitlatt marked this pull request as ready for review April 24, 2024 08:09
@priitlatt priitlatt merged commit a947b60 into master Apr 24, 2024
11 checks passed
@priitlatt priitlatt deleted the bugfix/asc-resource-empty-relationships branch April 24, 2024 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants