Skip to content

Commit cef0425

Browse files
committed
Return default collection when no table is given.
1 parent fcd6037 commit cef0425

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

django_mongodb/compiler.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,17 @@ def project_field(column):
435435

436436
@cached_property
437437
def collection_name(self):
438-
base_table = next(
439-
v
440-
for k, v in self.query.alias_map.items()
441-
if isinstance(v, BaseTable) and self.query.alias_refcount[k]
442-
)
438+
try:
439+
base_table = next(
440+
v
441+
for k, v in self.query.alias_map.items()
442+
if isinstance(v, BaseTable) and self.query.alias_refcount[k]
443+
)
444+
except StopIteration:
445+
query = self.query_class(self)
446+
query.aggregation_pipeline = [{"$facet": {"__null": []}}]
447+
self.subqueries.insert(0, query)
448+
return "__null"
443449
return base_table.table_alias or base_table.table_name
444450

445451
@cached_property

0 commit comments

Comments
 (0)