Skip to content

Commit

Permalink
Avoid using assert statements for actual business logic:
Browse files Browse the repository at this point in the history
Depending on what flags the python interpreter is launched with, they may
not even get checked when running in production.
  • Loading branch information
lukasgraf committed Apr 29, 2024
1 parent 9f49da3 commit 8ba1de6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion opengever/dossiertransfer/api/base.py
Expand Up @@ -34,7 +34,9 @@ def serialize(self, transfer, full_content=False):
(transfer, getRequest()), ISerializeToJson)()

if full_content:
assert self.has_valid_token()
if not self.has_valid_token():
raise Unauthorized

with elevated_privileges():
serialized['content'] = FullTransferContentSerializer(transfer)()

Expand Down
1 change: 0 additions & 1 deletion opengever/dossiertransfer/api/get.py
Expand Up @@ -97,7 +97,6 @@ def stream_document_blob(self):
if document_uid not in transfer.documents:
raise Unauthorized

assert len(brains) == 1
document = brains[0].getObject()
namedfile = document.file

Expand Down
4 changes: 2 additions & 2 deletions opengever/dossiertransfer/api/post.py
Expand Up @@ -69,8 +69,8 @@ def reply(self):
session.flush()

token = transfer.issue_token()
assert transfer.token == token
assert transfer.is_valid_token(token)
if not (transfer.token == token and transfer.is_valid_token(token)):
raise Unauthorized

serialized_transfer = self.serialize(transfer)

Expand Down
5 changes: 4 additions & 1 deletion opengever/dossiertransfer/api/serializers.py
Expand Up @@ -116,7 +116,10 @@ def __call__(self):
serialized_dossiers.append(serialized)

# We only add participations for the root dossier
assert serialized_dossiers[0]['UID'] == self.transfer.root
if serialized_dossiers[0]['UID'] != self.transfer.root:
raise RuntimeError(
'Unexpected first dossier, expected it to match root dossier')

serialized_dossiers[0]['participations'] = ParticipationsSerializer(self.transfer)()

return serialized_dossiers
Expand Down

0 comments on commit 8ba1de6

Please sign in to comment.