codemagic-ci-cd / cli-tools

Various utilities to managing Android and iOS app builds, code signing, and deployment.
https://codemagic.io/start/
GNU General Public License v3.0
267 stars 42 forks source link

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

Closed priitlatt closed 6 months ago

priitlatt commented 7 months ago

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 ```python 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) :18: in __init__ ??? _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = App.Relationships(appInfos=Relationship(links=, 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.