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

UserTask log entries shown on the wrong user #707

Open
ibot3 opened this issue Mar 30, 2024 · 3 comments
Open

UserTask log entries shown on the wrong user #707

ibot3 opened this issue Mar 30, 2024 · 3 comments

Comments

@ibot3
Copy link
Member

ibot3 commented Mar 30, 2024

Currently, the task logs are shown in the log table of the author of the tasks.
However, this is not intended, as the task logs should be shown in the log table of the target user.

I am not sure, but maybe the relationship is inconsistent.
The relationship on TaskLogEntry side seems to be correct:

user: Mapped[User] = relationship(
primaryjoin="TaskLogEntry.task_id == UserTask.id",
secondary="user_task",
back_populates="task_log_entries",
viewonly=True,
)

But on the user site, the join condition is missing:

task_log_entries: Mapped[list[TaskLogEntry]] = relationship(
back_populates="user", viewonly=True
)

SQLA maybe does a relationship with the author instead because of that?
(Commit a7efe20#diff-8d7fe1e2c7af484e9b87c16b9981b631d191918ca6886c1c17cb3c2b08546afd)

Another bug I noticed: Opening the tab for just the task logs shows error 404

@lukasjuhrich
Copy link
Collaborator

The latter thing is a typo:

LogType = t.Literal["user", "room", "hades", "task", "all"]
LOG_TYPES = frozenset(t.get_args(LogType))
def is_log_type(type: str) -> t.TypeGuard[LogType]:
return type in LOG_TYPES

log_table_tasks=LogTableSpecific(data_url=_log_endpoint(logtype="tasks")),

@lukasjuhrich
Copy link
Collaborator

Regarding the first thing, the question would be why user.task_log_entries does not contain those log entries which refer to the user, right? so a test skeleton might be something like

def test_user_backref_task_log_entries(session, user, processor):
    session.add(task := UserTask(
        creator=processor,
        user=user,
        # … (other attributes)
    ))
    session.add(le := TaskLogentry(message="foo", task=task, author=processor))
    session.flush()
    assert le.user == user
    assert user.task_log_entries == [le]

…correct?

@ibot3
Copy link
Member Author

ibot3 commented Mar 31, 2024

Correct AFAICS.

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

No branches or pull requests

2 participants