Re: .isset() behaviour change on StringHTMLProperty

"John P. Rouillard" <[email protected]>
Newsgroups gmane.comp.bug-tracking.roundup.user
Message-ID <[email protected]>
Hi Nagy:

In message <20210801110657.43caf6f4@Dell>,
Nagy Gabor writes:
>There is no default_value in my schema.py at all, and
>hyperdb.issue.get() returns None for unset string properties in
>question.
>
>Yes, I saw the test "return self._value is not None", so I think the
>None string property is changed somewhere to "". And so my original
>report was loose: I should have said that isset() always reports True
>for String poperties, no matter what I do.
>
>Yes, commenting out the lines
>if self._value is None:
>    self._value = prop.get_default_value()
>fixes the issue, so somehow prop.get_default_value() sets the wrong
>value.
>
>And yes, I think the problem is in String(_Type) of hyperdb.py:
>    def __init__(self, indexme='no', required=False, default_value="",
>                 quiet=False):
>...
>
>Probably there is a reason for this default value, but this breaks
>isset()...

Yeah, that value in __init__ would do it. It was added on:

  changeset:   4481:9bbf3758c16a
  user:        Stefan Seefeld <[email protected]>
  date:        Thu Apr 14 12:47:48 2011 +0000
  files:       roundup/cgi/templating.py roundup/hyperdb.py
  description:
  Allow default value declaration in DB schema.

no indication why String's default value is "" and not None.

Also this changeset replaced:

-            if isinstance(prop, hyperdb.Multilink):
-                value = []
-            else:
-                value = None
+            value = prop.get_default_value()

so this is the changeset that defined get_default_value. Before this
changeset the value used to be None for String if I understand this
correctly.

I am running the testsuite now, but my change to  String(_Type) of hyperdb.py:

   def __init__(self, indexme='no', required=False, default_value=None,
                quiet=False):

So default_value="" is replaced with None.

It's possible templating doesn't convert None -> "" when displaying it
in the web interface. There may be an explicit check for "" on the
property somewhere. Sadly the test suite doesn't have good coverage
for templating.

Can you use 2.1.0's templating.py and try changing the __init__
definition in hyperdb.py String(_Type) class to use
default_value=None. See if that:

  1. fixes the isset issue
  2. causes a display or other problem if a string property is unset.

Thanks and have a great day.

--
				-- rouilj
John Rouillard
===========================================================================
My employers don't acknowledge my existence much less my opinions.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.