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

Implement __eq__ on on Table #1075

Open
Skelmis opened this issue Sep 14, 2024 · 2 comments
Open

Implement __eq__ on on Table #1075

Skelmis opened this issue Sep 14, 2024 · 2 comments

Comments

@Skelmis
Copy link
Collaborator

Skelmis commented Sep 14, 2024

It'd be lovely to be able to compare table instances at a top level without the need to dive down into attributes. Further, users could always override the default id comparison on tables if they do special things.

An example use case of mine:

    @post(
        path="/{project_id:str}/settings/toggle_public_view",
        include_in_schema=False,
    )
    async def toggle_public_view(self, request: Request, project_id: str) -> Redirect:
        project, redirect = await self.get_project(request, project_id)
        if redirect:
            return redirect

        if project.owner != request.user:
            alert(
                request,
                "You must be the project owner to change project visibility.",
                level="error",
            )
            return project.redirect_to()

However with the current behavior the following occurs:

        project.owner.id == request.user.id -> True
        project.owner == request.user -> False
@Skelmis
Copy link
Collaborator Author

Skelmis commented Sep 14, 2024

An example __eq__ to this is as follows:

    def __eq__(self, other):
        return isinstance(other, self.__class__) and self.id == other.id

@dantownsend
Copy link
Member

That's a nice idea - I think it makes sense to add it.

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

No branches or pull requests

2 participants