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

date intervals cannot use from_string #45

Open
Marcnuth opened this issue Jan 3, 2018 · 1 comment
Open

date intervals cannot use from_string #45

Marcnuth opened this issue Jan 3, 2018 · 1 comment

Comments

@Marcnuth
Copy link

Marcnuth commented Jan 3, 2018

Problem & Codes

Running following codes, a type error will be raised:

DateInterval.from_string('[(2000-01-01),]')

Error Details

self = <[AttributeError("'DateInterval' object has no attribute 'lower_inc'") raised in repr()] DateInterval object at 0x3730ef0>
value = '2000-01-01'

def coerce_string(self, value):
   return self.type(value)

E TypeError: an integer is required (got type str)

@tachyondecay
Copy link

I ran into this via kvesteri/sqlalchemy-utils#392 and wanted to see if I could get it working simply. Digging deeper, it looks like this fails because native date objects don't easily parse string input into dates. Since DateInterval's type property is set to date, this causes coerce_string to fail.

I tried working around this by subclassing date, but my solution broke the creation of DateInterval instances through other means. It looks like coerce_value expects a lot out of type. I could probably get everything working but only in a hacky, sub-par way. Also, my solution relied on date.fromisoformat(), which is Python 3.7+.

I would probably take refuge in arrow because I love how much it makes date-handling and parsing easier, but that would add another dependency. Even then I'm not familiar enough with how intervals wants to use the type property to make sure it's handled gracefully.

Anyway, I hope this helps someone braver/better/with more time than me to tackle this when they have a chance.

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

No branches or pull requests

2 participants