Open MisterNando opened 6 years ago
Tagging @millerdev , per @czue's recommendation.
@MisterNando this is a strange error. I'm unable to tell from the given traceback how as_sql()
is being called with extra arguments. Can you find out what code is calling as_sql()
when the error occurs?
If you cannot do that, can you find out what the values of args
and kwargs
are when the error occurs? Maybe temporarily add a print statement to the method and capture the output:
class CTEUpdateQueryCompiler(SQLUpdateCompiler):
def as_sql(self, *args, **kwargs):
print(args, kwargs) # <---- capture the output of this when the error occurs
def _as_sql():
return super(CTEUpdateQueryCompiler, self).as_sql(*args, **kwargs)
return CTECompiler.generate_sql(self.connection, self.query, _as_sql)
Thanks for responding, @millerdev ! I can no longer reproduce the conditions that resulted in the error; however, I was able to dig up a more detailed stacktrace from our log archives:
[07/Sep/2018 09:00:00]::ERROR::api.py:34::as_sql() takes exactly 1 argument (3 given)
File "./asset_api/api/asset_checkin/api.py", line 27, in post
handler.resend_jobs_on_agent_request()
File "./asset_api/api/asset_checkin/utils.py", line 95, in resend_jobs_on_agent_request
).update(outcome_id=Globals.Outcome.Errored)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 647, in update
rows = query.get_compiler(self.db).execute_sql(CURSOR)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 1199, in execute_sql
cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 871, in execute_sql
sql, params = self.as_sql()
File "/usr/local/lib/python2.7/dist-packages/django_cte/query.py", line 113, in as_sql
return CTECompiler.generate_sql(self.connection, self.query, _as_sql)
File "/usr/local/lib/python2.7/dist-packages/django_cte/query.py", line 80, in generate_sql
base_sql, base_params = as_sql()
File "/usr/local/lib/python2.7/dist-packages/django_cte/query.py", line 112, in _as_sql
return super(CTEUpdateQueryCompiler, self).as_sql(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 1187, in as_sql
where, params = self.compile(self.query.where)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 373, in compile
sql, params = node.as_sql(self, self.connection)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/where.py", line 79, in as_sql
sql, params = compiler.compile(child)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 373, in compile
sql, params = node.as_sql(self, self.connection)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/lookups.py", line 381, in as_sql
return super(In, self).as_sql(compiler, connection)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/lookups.py", line 170, in as_sql
rhs_sql, rhs_params = self.process_rhs(compiler, connection)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/lookups.py", line 372, in process_rhs
return super(In, self).process_rhs(compiler, connection)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/lookups.py", line 229, in process_rhs
return super(FieldGetDbPrepValueIterableMixin, self).process_rhs(compiler, connection)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/lookups.py", line 100, in process_rhs
sql, params = compiler.compile(value)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 373, in compile
sql, params = node.as_sql(self, self.connection)
File "/usr/local/lib/python2.7/dist-packages/django_cte/query.py", line 113, in as_sql
return CTECompiler.generate_sql(self.connection, self.query, _as_sql)
File "/usr/local/lib/python2.7/dist-packages/django_cte/query.py", line 80, in generate_sql
base_sql, base_params = as_sql()
File "/usr/local/lib/python2.7/dist-packages/django_cte/query.py", line 112, in _as_sql
return super(CTEUpdateQueryCompiler, self).as_sql(*args, **kwargs)
TypeError: as_sql() takes exactly 1 argument (3 given)
It looks like the Django SQLCompiler is calling as_sql() with itself and the DB connection as arguments (line 373 in compiler.py).
Does this provide you with the information that you need to proceed with your debugging?
CTEUpdateQueryCompiler inherits from SQLUpdateCompiler, and overrides its as_sql method. However, the overridden method accepts arguments, whereas the parent method does not*, and the child method tries to pass those arguments to the parent method, resulting in a TypeError (see below).
*at least not in the current version of Django, and as far back as 1.11.4
Child method:
Parent method:
Observed error: