Skip to content

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

Closed
wants to merge 2 commits into from

Conversation

fyhertz
Copy link

@fyhertz fyhertz commented Dec 15, 2020

No description provided.

@fyhertz fyhertz changed the title Fix/nullable dates Fix nullable date/datetime properties Dec 15, 2020
@codecov
Copy link

codecov bot commented Dec 15, 2020

Codecov Report

Merging #267 (48a2ac6) into main (3ca219c) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3ca219c...48a2ac6. Read the comment docs.

Copy link
Collaborator

@dbanty dbanty left a 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 %}
Copy link
Collaborator

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:

Suggested change
{% 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 %}
Copy link
Collaborator

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

@dbanty dbanty added this to the 0.7.3 milestone Dec 15, 2020
Comment on lines +4 to +5
{{ property.python_name }} = {{ source }}
{{ property.python_name }} = isoparse({{ property.python_name }}).date() if {{ property.python_name }} else None
Copy link
Contributor

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:

Suggested change
{{ 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.

Copy link
Author

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!

dbanty added a commit that referenced this pull request Dec 21, 2020
@dbanty dbanty requested review from emann and removed request for emann December 21, 2020 21:34
@dbanty dbanty mentioned this pull request Dec 21, 2020
@dbanty
Copy link
Collaborator

dbanty commented Dec 21, 2020

I pulled this code into #277 and made the suggested change. Thanks again!

@dbanty dbanty closed this Dec 21, 2020
@fyhertz fyhertz deleted the fix/nullable-dates branch May 10, 2023 15:39
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.

3 participants