-
Notifications
You must be signed in to change notification settings - Fork 53
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: Handle empty lists in TAXII status responses #81
Conversation
In the commit message, when I say these elements are optional, I'm referring to section 4.3.1 of the TAXII 2.1 spec:
Let me know if there are other considerations I've missed. |
Codecov Report
@@ Coverage Diff @@
## master #81 +/- ##
=======================================
Coverage 94.89% 94.89%
=======================================
Files 8 8
Lines 1784 1784
=======================================
Hits 1693 1693
Misses 91 91
Continue to review full report at Codecov.
|
taxii2client/v21/__init__.py
Outdated
self.pendings = pendings or [] # optional | ||
self.successes = successes or None # optional | ||
self.failures = failures or None # optional | ||
self.pendings = pendings or None # optional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically these don't need the or None
at all any more, but handling it like this also deals with situations when the element might be otherwise falsey and cause confusion. I've not seen that occur though, so happy to simplify this if something things it's pointless.
Hi @maybe-sybr, thanks for the PR. Is there a specific bug you ran into that this will fix? Leaving them as |
Hi @clenk. Yep, this manifests when I use a custom backend in the You mentioned that changing the default to def __init__(.., successes=None, ..):
self._successes = successes
@property
def successes(self):
if self._successes is None: return []
return self._successes and use Any preference? I'll amend the PR when I see a reply. Thanks! |
@maybe-sybr that makes sense. Yeah, patterns like what you mentioned is what I had in mind about breaking. I think we should take out that part. Also, can you add your success_count, et al fix to the Forgive me for being obtuse (maybe I need coffee) but what is the advantage of your |
Using a private member and exposing it with a property would let us use {
"success_count": <non-zero>,
"successes": [],
} rather than omitting the I'll get an amended diff for you shortly and will take the |
These elements of the response are optional, so we should accept situations when they aren't provided at all. This change simply checks if the iterable `successes`, `pendings` and `failures` are truthy prior to verifying that their lengths match the associated `*_count` attribute. As such, we now accept status responses which return empty lists for these elements as well as responses which omit them entirely. Change-Id: I0ff802b9722c536144403a33e399c73fd29bdc61
bd21de4
to
0bdf84e
Compare
@clenk - sorry about the delay, got caught up with other stuff yesterday. I've just pushed an updated diff which is pretty minimal and should be fine if we're cool with not exploding on responses like the one I mocked in my previous comment. I'm happy to move forward with this diff. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, thank you @maybe-sybr!
These elements of the response are optional, so we should handle
situations when they aren't provided at all.