From f479df7f8d03ab767bb5e5d655243191087d6432 Mon Sep 17 00:00:00 2001 From: Daniyal Date: Wed, 24 Mar 2021 11:15:08 +0530 Subject: Refs #32508 -- Raised Type/ValueError instead of using "assert" in django.db.models. Co-authored-by: Mariusz Felisiak --- django/db/models/sql/query.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'django/db/models/sql') diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 2412e6ad4e..b3d92d786c 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -567,14 +567,14 @@ class Query(BaseExpression): The 'connector' parameter describes how to connect filters from the 'rhs' query. """ - assert self.model == rhs.model, \ - "Cannot combine queries on two different base models." + if self.model != rhs.model: + raise TypeError('Cannot combine queries on two different base models.') if self.is_sliced: raise TypeError('Cannot combine queries once a slice has been taken.') - assert self.distinct == rhs.distinct, \ - "Cannot combine a unique query with a non-unique query." - assert self.distinct_fields == rhs.distinct_fields, \ - "Cannot combine queries with different distinct fields." + if self.distinct != rhs.distinct: + raise TypeError('Cannot combine a unique query with a non-unique query.') + if self.distinct_fields != rhs.distinct_fields: + raise TypeError('Cannot combine queries with different distinct fields.') # Work out how to relabel the rhs aliases, if necessary. change_map = {} -- cgit v1.3