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

plugin support for Model.objects.extra #2488

Open
asottile-sentry opened this issue Jan 16, 2025 · 1 comment
Open

plugin support for Model.objects.extra #2488

asottile-sentry opened this issue Jan 16, 2025 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@asottile-sentry
Copy link

this is similar to .annotate but slightly different / more manual querying

an example from some sentry code:

        commit_results = list(
            Commit.objects.extra(
                select={"group_id": "sentry_grouplink.group_id"},
                tables=["sentry_grouplink"],
                where=[
                    "sentry_grouplink.linked_id = sentry_commit.id",
                    "sentry_grouplink.group_id IN ({})".format(
                        ", ".join(str(i.id) for i in resolved_groups)
                    ),
                    "sentry_grouplink.linked_type = %s",
                    "sentry_grouplink.relationship = %s",
                ],
                params=[int(GroupLink.LinkedType.commit), int(GroupLink.Relationship.resolves)],
            )
        )
        _commit_resolutions = {
            i.group_id: d for i, d in zip(commit_results, serialize(commit_results, user))   # error here
        }

would probably be pretty tricky to get the exact types out -- but at the very least I would rather have mypy understand that group_id attribute exists

@sobolevn
Copy link
Member

I agree, very cool feature! We can start small: with adding extra attributes that users define in the query with Any as the type.

@sobolevn sobolevn added enhancement New feature or request help wanted Extra attention is needed labels Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Development

No branches or pull requests

2 participants