We are using raw sql query views in our Django 1.9 project. That queries could be unicode objects with unicode symbols in it. Database that is used with project is Oracle Database Standard 12.2.
There is problem with sentry_sdk sql tracer when we are using DjangoIntegration module with our project. It causes our code to fail with error:
(part of related python exception trace)
File "/srv/app/local/lib/python2.7/site-packages/sentry_sdk/integrations/django/init.py", line 393, in execute
hub, self.cursor, sql, params, paramstyle="format", executemany=False
File "/usr/lib/python2.7/contextlib.py", line 17, in enter
return self.gen.next()
File "/srv/app/local/lib/python2.7/site-packages/sentry_sdk/tracing.py", line 363, in record_sql_queries
query = _format_sql(cursor, query)
File "/srv/app/local/lib/python2.7/site-packages/sentry_sdk/tracing.py", line 344, in _format_sql
return real_sql or str(sql)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 134-141: ordinal not in range(128)
Problem is that _format_sql tries to convert unicode object (sql = u'select foo from bar;') into str object.
This simple code inside _format_sql function fixed problem for me:
if isinstance(sql, unicode):
sql = sql.encode('utf-8')
But maybe that is not best fix for that problem.
We are using raw sql query views in our Django 1.9 project. That queries could be unicode objects with unicode symbols in it. Database that is used with project is Oracle Database Standard 12.2.
There is problem with sentry_sdk sql tracer when we are using DjangoIntegration module with our project. It causes our code to fail with error:
(part of related python exception trace)
File "/srv/app/local/lib/python2.7/site-packages/sentry_sdk/integrations/django/init.py", line 393, in execute
hub, self.cursor, sql, params, paramstyle="format", executemany=False
File "/usr/lib/python2.7/contextlib.py", line 17, in enter
return self.gen.next()
File "/srv/app/local/lib/python2.7/site-packages/sentry_sdk/tracing.py", line 363, in record_sql_queries
query = _format_sql(cursor, query)
File "/srv/app/local/lib/python2.7/site-packages/sentry_sdk/tracing.py", line 344, in _format_sql
return real_sql or str(sql)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 134-141: ordinal not in range(128)
Problem is that _format_sql tries to convert unicode object (sql = u'select foo from bar;') into str object.
This simple code inside _format_sql function fixed problem for me:
But maybe that is not best fix for that problem.