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: Remove mutable default usage from Keystore model declaration #284

Merged
merged 8 commits into from
Nov 4, 2022

Conversation

priitlatt
Copy link
Contributor

@priitlatt priitlatt commented Nov 4, 2022

Fixes #282.

Python 3.11 introduced a more strict check for default values of dataclass fields: https://docs.python.org/3/whatsnew/3.11.html#dataclasses

Since codemagic.models.Keystore defined field certificate_attributes as

@dataclass
class Keystore:
    ...
    certificate_attributes: CertificateAttributes = CertificateAttributes()

where CertificateAttributes is dataclass on its own, this caused a ValueError.

Stacktrace
>>> from codemagic.models import Keystore
Traceback (most recent call last):
  File "", line 1, in 
  File "/Users/priit/.pyenv/versions/3.11.0/lib/python3.11/site-packages/codemagic/models/__init__.py", line 12, in 
    from .keystore import Keystore
  File "/Users/priit/.pyenv/versions/3.11.0/lib/python3.11/site-packages/codemagic/models/keystore.py", line 7, in 
    @dataclass
     ^^^^^^^^^
  File "/Users/priit/.pyenv/versions/3.11.0/lib/python3.11/dataclasses.py", line 1221, in dataclass
    return wrap(cls)
           ^^^^^^^^^
  File "/Users/priit/.pyenv/versions/3.11.0/lib/python3.11/dataclasses.py", line 1211, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/priit/.pyenv/versions/3.11.0/lib/python3.11/dataclasses.py", line 959, in _process_class
    cls_fields.append(_get_field(cls, name, type, kw_only))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/priit/.pyenv/versions/3.11.0/lib/python3.11/dataclasses.py", line 816, in _get_field
    raise ValueError(f'mutable default {type(f.default)} for field '
ValueError: mutable default  for field certificate_attributes is not allowed: use default_factory

@priitlatt priitlatt marked this pull request as ready for review November 4, 2022 11:59
@priitlatt priitlatt added the bug Something isn't working label Nov 4, 2022
@priitlatt priitlatt merged commit f037c3f into master Nov 4, 2022
@priitlatt priitlatt deleted the bugfix/keystore-mutable-default branch November 4, 2022 12:10
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.

Crash in app-store-connect on Python 3.11
1 participant