[FIX] orm field (new api): preserve empty values instead of folding to False
The new API introduced a small behavior change where empty string values written or stored in a char/text field were replaced by False (i.e. as if they were NULL). This was done to mimic the web client behavior, but introduces a very surprising effect: a.name = ""; assert a.name == ""; would fail. It would also require many more tests in the code when reading existing required values from the database, as they could still be False when an empty string value had previously been stored, for some reason.
This commit is contained in:
parent
1644708fe8
commit
bd3df7bfa1
|
@ -967,8 +967,9 @@ class Char(_String):
|
||||||
_description_size = property(attrgetter('size'))
|
_description_size = property(attrgetter('size'))
|
||||||
|
|
||||||
def convert_to_cache(self, value, record, validate=True):
|
def convert_to_cache(self, value, record, validate=True):
|
||||||
return bool(value) and ustr(value)[:self.size]
|
if value is None or value is False:
|
||||||
|
return False
|
||||||
|
return ustr(value)[:self.size]
|
||||||
|
|
||||||
class Text(_String):
|
class Text(_String):
|
||||||
""" Text field. Very similar to :class:`Char`, but typically for longer
|
""" Text field. Very similar to :class:`Char`, but typically for longer
|
||||||
|
@ -981,15 +982,18 @@ class Text(_String):
|
||||||
type = 'text'
|
type = 'text'
|
||||||
|
|
||||||
def convert_to_cache(self, value, record, validate=True):
|
def convert_to_cache(self, value, record, validate=True):
|
||||||
return bool(value) and ustr(value)
|
if value is None or value is False:
|
||||||
|
return False
|
||||||
|
return ustr(value)
|
||||||
|
|
||||||
class Html(_String):
|
class Html(_String):
|
||||||
""" Html field. """
|
""" Html field. """
|
||||||
type = 'html'
|
type = 'html'
|
||||||
|
|
||||||
def convert_to_cache(self, value, record, validate=True):
|
def convert_to_cache(self, value, record, validate=True):
|
||||||
return bool(value) and html_sanitize(value)
|
if value is None or value is False:
|
||||||
|
return False
|
||||||
|
return html_sanitize(value)
|
||||||
|
|
||||||
|
|
||||||
class Date(Field):
|
class Date(Field):
|
||||||
|
|
Loading…
Reference in New Issue