~sircmpwn/sr.ht-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH core.sr.ht] Fixing IntFlag/Enum value validation.

Peter Sanchez
Details
Message ID
<20200624193443.26125-1-peter@netlandish.com>
DKIM signature
missing
Download raw message
Patch: +2 -2
I noticed when using the API to import tickets that setting proper
status/resolution values (according to the docs) was not passing
validation. Digging into the code the issue is as follows, using
TicketStatus (class IntFlag) from todosrht.types.ticketstatus:

TicketStatus('reported')

This is invalid Python for IntFlag/Enum classes. Since the validation
checks for ValueError, it was sort of swallowing the actual issue. The
correct method to access the enum value by name is:

TicketStatus['reported']

I didn't update the ValueError check because key is already verified
above the value fetching. I think the actual try/except can be removed
in this particular case but I wasn't sure if it would affect other
corners of the platform.

---
 srht/validation.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/srht/validation.py b/srht/validation.py
index bc3ed0a..f58dbd1 100644
--- a/srht/validation.py
+++ b/srht/validation.py
@@ -109,12 +109,12 @@ class Validation:
                if not isinstance(value, str):
                    self.error("{} should be an str".format(name), field=name)
                else:
                    if value not in (m[0] for m in cls.__members__.items()):
                    if value not in cls.__members__.keys():
                        self.error("{} should be a valid {}".format(name, cls.__name__),
                                field=name)
                    else:
                        try:
                            value = cls(value)
                            value = cls[value]
                        except ValueError:
                            self.error('{} is not a valid {}'.format(
                                value, cls.__name__), field=name)
-- 
2.17.1
Details
Message ID
<C3TO9WHCT02R.SW90DF5D7KDU@homura>
In-Reply-To
<20200624193443.26125-1-peter@netlandish.com> (view parent)
DKIM signature
pass
Download raw message
Thanks!

To git@git.sr.ht:~sircmpwn/core.sr.ht
   a7f1e30..c19708e  master -> master
Review patch Export thread (mbox)