diff roundup/backends/back_anydbm.py @ 8534:1f8492d68aca

bug: using 'null' value for attributes causes error. In rest.py, filter out any attributes that are set to 'None'. GET on an endpoint can return 'null' values when the attribute is unset. E.G. for a user: { "address": "baddy@example.com", "alternate_addresses": null, "last_login": "2026-03-18.05:57:09", "organisation": null, "password": null, "phone": null, "queries": [], "realname": "Fred Jones", "roles": "User", "timezone": null, "username": "badeggs" } But this json can not be submitted to a PUT or POST endpoint. The validators for passwords, strings, integers etc. don't expect a None value. This change handles attributes with "null" (None) values in json objects by filtering them from the python object before processing. The null value can't be used to unset an attribute via PUT or POST. The 'remove' action using the PATCH verb can unset the value. Also there appears to be some missing checks in the back_anydbm and rdbms_common files for the password type. All the other types have a check: value is not None and not isinstance(.....) but passwords only have the 'not isinstance(....)' part. Not sure why this was the case. Looking at commit history didn't make me think it was intentional.
author John Rouillard <rouilj@ieee.org>
date Wed, 18 Mar 2026 17:24:14 -0400
parents be227ab4c2e1
children
line wrap: on
line diff
--- a/roundup/backends/back_anydbm.py	Wed Mar 18 11:11:03 2026 -0400
+++ b/roundup/backends/back_anydbm.py	Wed Mar 18 17:24:14 2026 -0400
@@ -984,7 +984,7 @@
                         (self.classname, newid, key), value)
 
             elif isinstance(prop, hyperdb.Password):
-                if not isinstance(value, password.Password):
+                if value is not None and not isinstance(value, password.Password):
                     raise TypeError('new property "%s" not a Password' % key)
 
             elif isinstance(prop, hyperdb.Date):
@@ -1344,7 +1344,7 @@
                         value)
 
             elif isinstance(prop, hyperdb.Password):
-                if not isinstance(value, password.Password):
+                if value is not None and not isinstance(value, password.Password):
                     raise TypeError('new property "%s" not a '
                                     'Password' % propname)
                 propvalues[propname] = value

Roundup Issue Tracker: http://roundup-tracker.org/