Skip to content

Commit

Permalink
Ward for None in is_valid_object()
Browse files Browse the repository at this point in the history
  • Loading branch information
jleclanche committed Oct 13, 2022
1 parent e5eaa11 commit 29aaf77
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion djstripe/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ def is_valid_object(cls, data):
"""
Returns whether the data is a valid object for the class
"""
return "object" in data and data["object"] == cls.stripe_class.OBJECT_NAME
return data and data.get("object") == cls.stripe_class.OBJECT_NAME

def _attach_objects_hook(
self, cls, data, api_key=djstripe_settings.STRIPE_SECRET_KEY, current_ids=None
Expand Down
2 changes: 1 addition & 1 deletion djstripe/models/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ def __str__(self):

@classmethod
def is_valid_object(cls, data):
return "object" in data and data["object"] in ("invoiceitem", "line_item")
return data and data.get("object") in ("invoiceitem", "line_item")

def get_stripe_dashboard_url(self):
return self.invoice.get_stripe_dashboard_url()
Expand Down
2 changes: 1 addition & 1 deletion djstripe/models/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,4 @@ def is_valid_object(cls, data):
"""
Returns whether the data is a valid object for the class
"""
return "object" in data and data["object"] == "transfer_reversal"
return data and data.get("object") == "transfer_reversal"
2 changes: 1 addition & 1 deletion djstripe/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1654,7 +1654,7 @@ class File(StripeModel):

@classmethod
def is_valid_object(cls, data):
return "object" in data and data["object"] in ("file", "file_upload")
return data and data.get("object") in ("file", "file_upload")

def __str__(self):
return f"{self.filename}, {enums.FilePurpose.humanize(self.purpose)}"
Expand Down

0 comments on commit 29aaf77

Please sign in to comment.