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

fix: check default value existence if field value is None #210

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/infi/clickhouse_orm/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ def to_python(self, value, timezone_in_use):
return value
if isinstance(value, bytes):
return value.decode('UTF-8')
if value is None and self.default is not None:
return self.default
raise ValueError('Invalid value for %s: %r' % (self.__class__.__name__, value))


Expand Down Expand Up @@ -295,6 +297,8 @@ class BaseIntField(Field):
'''
def to_python(self, value, timezone_in_use):
try:
if value is None and self.default is not None:
return int(self.default)
return int(value)
except:
raise ValueError('Invalid value for %s - %r' % (self.__class__.__name__, value))
Expand Down Expand Up @@ -371,6 +375,8 @@ class BaseFloatField(Field):

def to_python(self, value, timezone_in_use):
try:
if value is None and self.default is not None:
return float(self.default)
return float(value)
except:
raise ValueError('Invalid value for %s - %r' % (self.__class__.__name__, value))
Expand Down