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

Change base class of TimeZoneSerializerField from DJRF's Field to CharField #137

Merged
merged 5 commits into from
Jul 7, 2024

Conversation

mfogel
Copy link
Owner

@mfogel mfogel commented Jul 7, 2024

What

  • change base class of TimeZoneSerializerField from DJRF's Field to CharField
  • add tests to ensure the required, allow_null, and allow_blank kwargs are all working as documented by DJRF

Why

Subclassing Field introduces some situations where it isn't clear what the correct behavior is. DJRF addressed this for CharField in their 3.0 release - let's leverage their solution here.

Closes #130

Copy link

codecov bot commented Jul 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.64%. Comparing base (bb20f86) to head (610a2c2).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #137      +/-   ##
==========================================
- Coverage   99.09%   98.64%   -0.46%     
==========================================
  Files          10       10              
  Lines         222      222              
==========================================
- Hits          220      219       -1     
- Misses          2        3       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mfogel mfogel merged commit 99394c9 into main Jul 7, 2024
69 of 70 checks passed
@mfogel mfogel deleted the mfogel/serializer-field-empty-values branch July 7, 2024 03:12
@gotounix
Copy link

gotounix commented Jul 10, 2024

@mfogel
I don't think changing Field to CharField is a good solution.
And this change is a BREAKING change.
Because in TimeZoneSerializerField 's __init__ using super().__init__(*args, **kwargs), but in CharField 's __init__ it does't support *arg:

class CharField(Field):
    ...

    def __init__(self, **kwargs):

Therefore, changing Field to CharField not only loses flexibility, but also makes all existing subclasses of TimeZoneSerializerField that using *args unusable. I believe a better solution is to use a custom validator instead of changing the original default behavior to fit the DRF's parameters.

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.

TimeZoneSerializerField should allow empty strings when required=False
2 participants