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

bug_fix(1477): type handling in _add_sql_comment #3113

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,9 @@ def _update_args_with_added_sql_comment(self, args, cursor) -> tuple:
args_list = list(args)
self._capture_mysql_version(cursor)
commenter_data = self._get_commenter_data()
# Convert sql statement to string, handling psycopg2.sql.Composable object
if hasattr(args_list[0], "as_string"):
args_list[0] = args_list[0].as_string(cursor.connection)
statement = _add_sql_comment(args_list[0], **commenter_data)
args_list[0] = statement
args = tuple(args_list)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def __call__(self, execute: Type[T], sql, params, many, context) -> T:
db_driver = context["connection"].settings_dict.get("ENGINE", "")
resolver_match = self.request.resolver_match

# Convert sql statement to string, handling psycopg2.sql.Composable object
if hasattr(sql, "as_string"):
sql = sql.as_string(context["connection"])

sql = _add_sql_comment(
sql,
# Information about the controller.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ def _before_cur_exec(
commenter_data = self._get_commenter_data(conn)

if self.enable_attribute_commenter:
# Convert sql statement to string, handling psycopg2.sql.Composable object
if hasattr(statement, "as_string"):
statement = statement.as_string(conn)
# sqlcomment is added to executed query and db.statement span attribute
statement = _add_sql_comment(
statement, **commenter_data
Expand Down
Loading