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

CLI: Fix error in aiida.cmdline.utils.log.CliFormatter #5957

Merged
merged 3 commits into from
Apr 11, 2023

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Apr 5, 2023

The CliFormatter could raise an exception if the record message contained named parameters, but the args is a tuple. An example is when the QueryBuilder would log the prepared SQL statement, e.g.:

SELECT t.pk FROM t WHERE t.pk = %(pk_1)s

The %(pk_1)s here is indeed a named parameter, but not intended to be formatted for the log message itself, but to be kept as is. However, the log formatter does not know this and would attempt to format it with the given args, which would be the empty tuple. This would raise:

TypeError: format requires a mapping

The CliFormatter.format didn't account for this case. Instead of fixing it there, the class now just refers to the base Formatter class to format the record, which does the right thing in this case, and the CliFormatter simply adds the prefix to the formatted message if necessary.

The `CliFormatter` could raise an exception if the record message
contained named parameters, but the `args` is a tuple. An example is
when the `QueryBuilder` would log the prepared SQL statement, e.g.:

    SELECT t.pk FROM t WHERE t.pk = %(pk_1)s

The `%(pk_1)s` here is indeed a named parameter, but not intended to be
formatted for the log message itself, but to be kept as is. However, the
log formatter does not know this and would attempt to format it with the
given `args`, which would be the empty tuple. This would raise:

    TypeError: format requires a mapping

The `CliFormatter.format` didn't account for this case. Instead of
fixing it there, the class now just refers to the base `Formatter` class
to format the record, which does the right thing in this case, and the
`CliFormatter` simply adds the prefix to the formatted message if
necessary.
@sphuber sphuber requested review from unkcpz and mbercx April 5, 2023 08:32
@sphuber
Copy link
Contributor Author

sphuber commented Apr 11, 2023

@unkcpz I would like to get this in before the release. Would you still have time to take a look or shall I request someone else?

@unkcpz
Copy link
Member

unkcpz commented Apr 11, 2023

I review it now 😉

Copy link
Member

@unkcpz unkcpz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sphuber thanks! looks all good to me!

@sphuber sphuber merged commit 3949c25 into aiidateam:main Apr 11, 2023
@sphuber sphuber deleted the fix/cli-formatter branch April 11, 2023 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants