-
-
Notifications
You must be signed in to change notification settings - Fork 228
Fix nullable date/datetime properties #267
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
Conversation
Codecov Report
@@ Coverage Diff @@
## main #267 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 46 46
Lines 1314 1314
=========================================
Hits 1314 1314 Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks! Probably another bug from 0.7.1 (FYI @packyg). I think we can simplify the template a bit, take a look at my suggestion.
@@ -1,6 +1,11 @@ | |||
{% macro construct(property, source, initial_value="None") %} | |||
{% if property.required %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead, couldn't we do this:
{% if property.required %} | |
{% if property.required and not property.nullable %} |
and let the below else handle None?
@@ -1,6 +1,11 @@ | |||
{% macro construct(property, source, initial_value="None") %} | |||
{% if property.required %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing here I think
{{ property.python_name }} = {{ source }} | ||
{{ property.python_name }} = isoparse({{ property.python_name }}).date() if {{ property.python_name }} else None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes as they are here would cause type issues, I think, because the type of {{property.python_name}}
changes from that of {{source}}
(Optional[str]
) to Optional[date]
You would need to put the {{source}}
in a temp variable for this implementation:
{{ property.python_name }} = {{ source }} | |
{{ property.python_name }} = isoparse({{ property.python_name }}).date() if {{ property.python_name }} else None | |
_{{ property.python_name }} = {{ source }} | |
{{ property.python_name }} = isoparse(_{{ property.python_name }}).date() if {{ property.python_name }} else None |
But I think @dbanty's suggestion would work and would be a bit simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I will try to fix that today!
I pulled this code into #277 and made the suggested change. Thanks again! |
No description provided.