Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Koncopd committed Dec 11, 2024
1 parent d547bbe commit 0ca3b78
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions lamindb/core/_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,21 @@ def get_artifact_with_related(
artifact, {i["featureset"]: i["slot"] for i in v}
)

m2m_any_expr = reduce(
lambda a, b: a | b,
(Q(**{f"{m2m_name}__isnull": False}) for m2m_name in m2m_relations),
)
# this is needed to avoid querying all m2m relations even if they are all empty
# this checks if non-empty m2m relations are present in the record
m2m_any = (
model.objects.using(artifact._state.db)
.filter(uid=artifact.uid)
.filter(m2m_any_expr)
.exists()
)
if len(m2m_relations) == 0:
m2m_any = False
else:
m2m_any_expr = reduce(
lambda a, b: a | b,
(Q(**{f"{m2m_name}__isnull": False}) for m2m_name in m2m_relations),
)
# this is needed to avoid querying all m2m relations even if they are all empty
# this checks if non-empty m2m relations are present in the record
m2m_any = (
model.objects.using(artifact._state.db)
.filter(uid=artifact.uid)
.filter(m2m_any_expr)
.exists()
)
if m2m_any:
m2m_data = related_data["m2m"]
for m2m_name in m2m_relations:
Expand Down

0 comments on commit 0ca3b78

Please sign in to comment.