Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Minor refactor to address self.client.submit_job(job) raising UnboundLocalError #57

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hum4n0id
Copy link
Contributor

Minor refactor in try, except block (146): when self.client.submit_job(job) raises an OSError, job_id is unassigned resulting in UnboundLocalError. This was brought to my attention this morning and I wanted to quickly address it.
Using job in place of job_id in the except block seemed appropriate as it's referencing a returned job_id two line above.

…b(job) raises an OSError, job_id is unassigned resulting in UnboundLocalError.
Copy link
Contributor

@plars plars left a comment

Choose a reason for hiding this comment

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

Good catch, thanks for that! We can't do it this way, but I think this can be partially addressed with some small changes. However, the bigger questions to me are:
Why couldn't it submit the job?
What failed?
Should it be retried instead?

At the very least, I think it's helpful to know if this was a server unreachable situation (we should probably retry at least a bit for that) or something wrong with the job, in which case we should pass along what it said, if anything useful.

@@ -146,14 +146,14 @@ def create_jobs(self):
try:
job_id = self.client.submit_job(job)
except OSError as exc:
logger.exception("Unable to create job: %s", job_id)
logger.exception("Unable to create job: %s", job)
Copy link
Contributor

Choose a reason for hiding this comment

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

You're right, we can't return the job_id here, but we shouldn't return the entire job json either. Perhaps the queue name that it would have gone on, and say "Unable to create job in queue: {...}"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense, I did not realize that we'd get the entire job json here.
Your other suggestion sounds reasonable to me - I'll try and implement this shortly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Were you still working on this patch?

@plars
Copy link
Contributor

plars commented Oct 20, 2023

@hum4n0id I don't know if this is still valid or not, but if it is, can you re-propose it against https://github.com/canonical/testflinger instead?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants