[FIX] fields: empty date or datetime
When the `create` or `write` method receives an empty string for a date or a datetime field, PostgreSQL will fail since this is not an accepted value for this field type. We fallback on `None` for falsy values. opw-1819336 @KangOl : watch out when forward-porting, the signature of `convert_to_column` has changed in saas-14.
This commit is contained in:
committed by
Nicolas Martinelli
parent
231cae2e7f
commit
2021f44c0e
@@ -1527,6 +1527,9 @@ class Date(Field):
|
||||
""" Convert a :class:`date` value into the format expected by the ORM. """
|
||||
return value.strftime(DATE_FORMAT) if value else False
|
||||
|
||||
def convert_to_column(self, value, record):
|
||||
return super(Date, self).convert_to_column(value or None, record)
|
||||
|
||||
def convert_to_cache(self, value, record, validate=True):
|
||||
if not value:
|
||||
return False
|
||||
@@ -1596,6 +1599,9 @@ class Datetime(Field):
|
||||
""" Convert a :class:`datetime` value into the format expected by the ORM. """
|
||||
return value.strftime(DATETIME_FORMAT) if value else False
|
||||
|
||||
def convert_to_column(self, value, record):
|
||||
return super(Datetime, self).convert_to_column(value or None, record)
|
||||
|
||||
def convert_to_cache(self, value, record, validate=True):
|
||||
if not value:
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user