Skip to content

[IMP] queue_job: handle non-existing method job#940

Open
RyanTranAVB wants to merge 1 commit into
OCA:18.0from
RyanTranAVB:18.0-handle-non-existing-method-job
Open

[IMP] queue_job: handle non-existing method job#940
RyanTranAVB wants to merge 1 commit into
OCA:18.0from
RyanTranAVB:18.0-handle-non-existing-method-job

Conversation

@RyanTranAVB

Copy link
Copy Markdown

When a Job is previously created with a valid method, at any point if job not yet executed and the method is no longer valid, job runner can be stuck trying to enqueue it. This commit allows to skip these jobs with proper exception and one can clean/fix them if needed.

@OCA-git-bot

Copy link
Copy Markdown
Contributor

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

Comment on lines +83 to +102
except JobMethodNotFound as exc:
# In case a job's method no longer exists, we don't want the runner
# to keep re-enqueuing it. Failing it here with exceptions. We use
# raw SQL here to avoid this update being rolled back due to savepoint.
exc_name = f"{exc.__class__.__module__}.{exc.__class__.__name__}"
exc_message = str(exc)
env.cr.execute(
"""
UPDATE queue_job
SET state = 'failed', exc_name = %s, exc_message = %s, exc_info = %s
WHERE uuid = %s AND state NOT IN ('done', 'cancelled', 'failed')
""",
(exc_name, exc_message, exc_message, job_uuid),
)
_logger.warning(
"Job %s references a non-existent method and was marked as failed",
job_uuid,
)
if not config["test_enable"]:
env.cr.commit()

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.

Both the raw SQL and the ORM are using the same cursor; the same savepoint?

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.

Perhaps job.in_temporary_env() and then ORM methods instead of raw SQL?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

that's good point, I was overthinking it cause JobMethodNotFound wont cause any rollback, so it's safe using the same cursor I guess.

in_temporary_env won't work here because it's failing during loading the job as getattr fails

@RyanTranAVB RyanTranAVB force-pushed the 18.0-handle-non-existing-method-job branch from db9e0e7 to af3bd94 Compare July 3, 2026 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:queue_job Module queue_job mod:test_queue_job Module test_queue_job series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants