Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove JoinQueryset.get_quoted_query() #618

Merged
merged 1 commit into from
May 2, 2024
Merged
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
19 changes: 2 additions & 17 deletions model_utils/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,21 +293,6 @@ class SoftDeletableManager(SoftDeletableManagerMixin, models.Manager):

class JoinQueryset(models.QuerySet):

def get_quoted_query(self, query):
query, params = query.sql_with_params()

# Put additional quotes around string.
params = [
f'\'{p}\''
if isinstance(p, str) else p
for p in params
]

# Cast list of parameters to tuple because I got
# "not enough format characters" otherwise.
params = tuple(params)
return query % params

def join(self, qs=None):
'''
Join one queryset together with another using a temporary table. If
Expand Down Expand Up @@ -349,7 +334,7 @@ def join(self, qs=None):
new_qs = self.model.objects.all()

TABLE_NAME = 'temp_stuff'
query = self.get_quoted_query(qs.query)
query, params = qs.query.sql_with_params()
sql = '''
DROP TABLE IF EXISTS {table_name};
DROP INDEX IF EXISTS {table_name}_id;
Expand All @@ -358,7 +343,7 @@ def join(self, qs=None):
'''.format(table_name=TABLE_NAME, fk_column=fk_column, query=str(query))

with connection.cursor() as cursor:
cursor.execute(sql)
cursor.execute(sql, params)

class TempModel(models.Model):
temp_key = models.ForeignKey(
Expand Down
Loading