Replies: 1 comment
-
For Relevant links/discussions we had
Laying some context to why it'd be useful. In the try/catch version, we need to test two branches. try:
user = user_repo.find_by_email_address('[email protected]')
except ObjectNotFoundError:
return # or handle it by raising another exception
if user.created_at > datetime(2019):
# do something
pass In this version, we only need to test one. user = user_repo.find_by_email_address('[email protected]')
# we need fewer test cases to reach desired coverage here
if user and user.created_at > datetime(2019):
# do something
pass |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
get
andfind_by
methods in DAOs throwObjectNotFoundError
exception on zero results. It would be good to optionally control the exception raising behavior, as needed by the application functionality. Currently, the only way to find an object without raising an exception is withquery.filter(<>).first
.Behavior in other packages:
SQLAlchemy's
get
returns None if no record was found. Flask SQLAlchemy package has aget_or_404
method, which is like get() but aborts with 404 if not found instead of returning None.Django's
get
raisesDoesNotExist
if no objects were found orMultipleObjectsReturned
if more than one object was found.There is no
find_by
method in Django.Options:
get
as-it-is withfind_by
andfind_first_by
find_first_by
does not raise exception where as the other two do.get
as-it-is withfind_by
andfind_by_or_raise
find_by
does not raise exception, butfind_by_or_raise
get
as-it-is withfind_by
andquery.filter(<>).first
get
andfind_by
continue to raise exceptions (current behavior).Beta Was this translation helpful? Give feedback.
All reactions