CCI-MOC / flocx-market

2 stars 9 forks source link

Use .one_or_none() instead of .first() in db get operations #112

Closed larsks closed 5 years ago

larsks commented 5 years ago

This replaces all calls to .first() in db/sqlachemy/api.py with .one_or_none(). This will preserve the current behavior in cases where there is a single match or not matches, but will (correctly) raise an exception if there are multiple matches.

Closes #111

codecov-io commented 5 years ago

Codecov Report

Merging #112 into master will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #112   +/-   ##
=======================================
  Coverage   92.96%   92.96%           
=======================================
  Files          49       49           
  Lines        1776     1776           
=======================================
  Hits         1651     1651           
  Misses        125      125
Impacted Files Coverage Δ
flocx_market/db/sqlalchemy/api.py 95.67% <ø> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update ccc107a...84fe8f4. Read the comment docs.

tzumainn commented 5 years ago

I think using one would be fine too; if we're in a function that passes in a UUID, and there's no match in the database, then I think something also went wrong. But I'm fine with this since I think @ljmcgann is adding further exception handling, and throwing a flocx_market-specific error if the query returns None would be fine too.

larsks commented 5 years ago

I went with one_or_none because this preserves the existing behavior of the code and I was aiming for the minimum change. Raising an exception in the case of no matches would require changes to a bunch of other code.