Skip to content
Discussion options

You must be logged in to vote

The problem is in the line

        org.users.append(LinkOrgUser(org=org, user=aa, role=1))

Creating an instance of LinkOrgUser will already link User to Organization, but you append this object to org.users and it creates duplicates.

I have no idea why it works differently with non-async session.
To fix your code example, just remove org.users.append():

    async with async_memory_session() as async_session:
        org = Organization(name="Example", id=UUID(int=5))
        aa = User(name="AA", id=UUID(int=6))
        LinkOrgUser(org=org, user=aa, role=1)  # <- this line was changed

        async_session.add(org)
        await async_session.commit()

        assert org.name == "Example"

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
2 participants