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

Add a task_name property to DBTaskResult #127

Merged
merged 1 commit into from
Dec 22, 2024

Conversation

tomkins
Copy link
Contributor

@tomkins tomkins commented Dec 18, 2024

Closes #126

Added a fairly simple method/property to DBTaskResult to return the task name based on the saved path in the database.

This does change the name of the column in the admin from "Task" to "Task name" - let me know if that's an issue at all.

@property
def task_name(self) -> str:
try:
return self.task_path.rsplit(".", 1)[1]
Copy link
Owner

Choose a reason for hiding this comment

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

Thought: It'd be nice to keep using task.name by default, but falling back to these 2 if it's not available.

@tomkins
Copy link
Contributor Author

tomkins commented Dec 20, 2024

Updated - and improved the tests a little bit this time round.

def test_task_name(self) -> None:
db_task_result = DBTaskResult.objects.create(
args_kwargs={"args": [], "kwargs": {}},
task_path="tests.tasks.noop_task",
Copy link
Owner

Choose a reason for hiding this comment

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

Suggestion: Given these tests are incredibly similar, it'd be better to use subTest to just add cases and expected values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in a965773

If a task still exists - use that for the name.

However if the underlying function no longer exists - use task_path to come up with an appropriate name to show in the admin.
@RealOrangeOne RealOrangeOne merged commit 20dab41 into RealOrangeOne:master Dec 22, 2024
48 checks passed
@tomkins tomkins deleted the removed-task-error branch December 22, 2024 16:42
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.

ImportError in Django admin when viewing result list that includes a deleted task
2 participants