Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions db/thing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ===============================================================================
from typing import List, TYPE_CHECKING
from datetime import date
from typing import List, TYPE_CHECKING

from sqlalchemy import Integer, ForeignKey, String, Column, Float, Text, Date
from sqlalchemy.ext.associationproxy import association_proxy, AssociationProxy
from sqlalchemy.orm import relationship, mapped_column, Mapped
Expand All @@ -27,11 +28,10 @@
Base,
ReleaseMixin,
)
from db.data_provenance import DataProvenanceMixin
from db.measuring_point_history import MeasuringPointHistory
from db.permission_history import PermissionHistoryMixin
from services.util import retrieve_latest_polymorphic_history_table_record
from db.status_history import StatusHistoryMixin
from db.measuring_point_history import MeasuringPointHistory
from db.data_provenance import DataProvenanceMixin
from services.util import retrieve_latest_polymorphic_history_table_record

if TYPE_CHECKING:
Expand Down Expand Up @@ -412,7 +412,7 @@ def measuring_point_height(self) -> int | None:

Since measuring_point_history is eagerly loaded, this should not introduce N+1 query issues.
"""
if self.thing_type == "water well":
if self.thing_type == "water well" and self.measuring_points:
sorted_measuring_point_history = sorted(
self.measuring_points, key=lambda x: x.start_date, reverse=True
)
Expand All @@ -428,7 +428,7 @@ def measuring_point_description(self) -> str | None:

Since measuring_point_history is eagerly loaded, this should not introduce N+1 query issues.
"""
if self.thing_type == "water well":
if self.thing_type == "water well" and self.measuring_points:
sorted_measuring_point_history = sorted(
self.measuring_points, key=lambda x: x.start_date, reverse=True
)
Expand Down
Loading