diff --git a/tests/test_deconstruct.py b/tests/test_deconstruct.py index 2a9614d..ec4c276 100644 --- a/tests/test_deconstruct.py +++ b/tests/test_deconstruct.py @@ -108,13 +108,16 @@ def test_specifying_defaults_not_frozen(): ], ) def test_deconstruct_when_using_choices(choices, use_pytz): - field = TimeZoneField(choices=choices) - _name, _path, args, kwargs = field.deconstruct() + field = TimeZoneField(choices=choices, use_pytz=use_pytz) + _name, _path, _args, kwargs = field.deconstruct() assert kwargs == { - "choices": [ - ("US/Pacific", "US/Pacific"), - ("US/Eastern", "US/Eastern"), - ] + **{ + "choices": [ + ("US/Pacific", "US/Pacific"), + ("US/Eastern", "US/Eastern"), + ] + }, + **({"use_pytz": use_pytz} if use_pytz is not None else {}), } diff --git a/timezone_field/fields.py b/timezone_field/fields.py index 5a5b21a..8a195c4 100644 --- a/timezone_field/fields.py +++ b/timezone_field/fields.py @@ -46,8 +46,8 @@ def __init__(self, *args, **kwargs): # https://github.com/django/django/blob/1.11.11/django/db/models/fields/__init__.py#L145 if len(args) > 3: raise ValueError("Cannot specify max_length by positional arg") + kwargs.setdefault("max_length", self.default_max_length) - self.max_length = kwargs.pop("max_length", self.default_max_length) self.use_pytz_explicit = kwargs.pop("use_pytz", None) self.use_pytz = self.use_pytz_explicit if self.use_pytz_explicit is not None else use_pytz_default() self.default_tzs = self.default_pytz_tzs if self.use_pytz else self.default_zoneinfo_tzs