Skip to content

[16.0][FIX] prevent a warning message - #644

Closed
benwillig wants to merge 1 commit into
OCA:16.0from
acsone:16.0-fix_exception_name_to_args0-bwi
Closed

benwillig wants to merge 1 commit into
OCA:16.0from
acsone:16.0-fix_exception_name_to_args0-bwi

Conversation

@benwillig

Copy link
Copy Markdown
Contributor

Use args[0] instead of name to get the exception message as the name attribute is deprecated

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @guewen,
some modules you are maintaining are being modified, check this out!

@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@simahawk simahawk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Additionally, could you pls rewrite the commit msg to something like

[fix] queue_job: fix exception msg handling

.... long explanation goes here...

Comment thread queue_job/controllers/main.py Outdated
if hasattr(orig_exception, "__module__"):
exception_name = orig_exception.__module__ + "." + exception_name
exc_message = getattr(orig_exception, "name", str(orig_exception))
exc_message = getattr(orig_exception, "args[0]", str(orig_exception))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are you sure the this instance has an attribute called "args[0]"? This seems broken to me 🤔
args will be always there and very likely you'll have a first arg.

I guess you want to have something like orig_exception.args[0] if orig_exception.args else str(orig_exception).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Per 8.3 Handling Exceptions 1,

The except clause may specify a variable after the exception name. The variable is bound to the exception instance which typically has an args attribute that stores the arguments. For convenience, builtin exception types define str() to print all the arguments without explicitly accessing .args.

"Typically" suggests that args will be absent some of the time.

  1. At the risk of having a slightly uglier error message, why not just use str(orig_exception) instead of trying to preserve formatting?
  2. If the exception handling behavior is changing, it should be covered by unit tests.

Footnotes

  1. https://docs.python.org/3/tutorial/errors.html#handling-exceptions ↩

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Indeed the syntax looks weird so your proposal would be better. However, @amh-mw made a point so I think it would be better to simply use str(orig_exception).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe I can give you a little background as I'm the author of this piece of code 😉

The aim was to clearly rip out of the msg the exception class. That's why we have exc_name and exc_message. Exceptions are already messy for end users and this is an attempt to have a better msg.
Not to mention that this proposal will cause duplication of info because the exc name will be repeated.
Hence, calling str was just a safe fallback to make sure you had a msg.

An alternative is to call str and drop surrounding chars like exc name, parentesis, etc but I find this more complex than the little check here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I updated the commit

@benwillig
benwillig force-pushed the 16.0-fix_exception_name_to_args0-bwi branch from 716304d to 43d0e46 Compare May 30, 2024 09:27
'name' attributes for odoo's exception has been deprecated and produces a warning message. This commit fixes the behavior
@benwillig
benwillig force-pushed the 16.0-fix_exception_name_to_args0-bwi branch from 43d0e46 to 8479b13 Compare May 30, 2024 09:29
@github-actions

Copy link
Copy Markdown

There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions Bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Sep 29, 2024
Azerty-Dick pushed a commit to Azerty-BV/oca-queue that referenced this pull request Oct 4, 2024
It doesn't make sense and even more, it crashed.

Fixes OCA#644
@github-actions github-actions Bot closed this Nov 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale PR/Issue without recent activity, it'll be soon closed automatically.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants