`get_result` should return an error if multiple rows are returned
#2,446 创建于 2020年6月29日
描述
Versions
All
Problem Description
RunQueryDsl provides several methods for accessing query results:
- execute (returns number of rows affected)
- load/get_results (returns all rows)
- get_result (returns a single row)
- first (returns the first row)
I expected that get_result would return an error if multiple rows are returned (to differentiate it from first). However, it seems that it will just return the first row. Other ORMs (SQLalchemy, Django ORM) will raise an exception in this case.
This is dangerous: if code is using get_result then it clearly expects a single row to be returned, and if multiple rows are returned, it's a sign that the query may be wrong, or accidentally missing filters which should be present. If this expectation is invalid, then diesel should report an error sooner rather than later.
Unfortunately, this is a breaking change to fix. Personally I think that's still worth it due to the danger not fixing it poses. However, I would also be OK with the documentation being updated to call out this fact, and a new method being added to assert that a single item is returned.