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

Django ORM query annotation with Right subparam does not accept F() expression #233

Open
yvsssantosh-condor opened this issue Apr 4, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@yvsssantosh-condor
Copy link

I have a django query where I'm splitting a string and getting a part of it in an ORM query. I get an error which says,

Argument of type "F" cannot be assigned to parameter "length" of type "Value | int" in the function "__init__"
Type "F" cannot be assigned to type "Value | int"
"F" is incompatible with "Value"
"F" is incompatible with "int"

Here is my query:

# MyModel fields
# abc_id

# Example abc_ids: `123_1`, `123_2`, `123_3`. `124_1`, `125_1`, etc.

from django.db.models import F, IntegerField, Value
from django.db.models.functions import Cast, Reverse, Right, StrIndex

MyModel.objects.annotate(
    last_index_of_underscore=StrIndex(Reverse(F('abc_id')), Value('_')),
    abc_no=Cast(
        Right('abc_id', F('last_index_of_underscore') - 1), IntegerField()
    )
)
@sbdchd sbdchd added the bug Something isn't working label Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants