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

Using NumericRange with IntegerRangeField generates invalid SQL with latest psycopg #209

Open
vbabiy opened this issue Oct 30, 2024 · 1 comment

Comments

@vbabiy
Copy link

vbabiy commented Oct 30, 2024

If you have a serializer like this with a IntegerRangeField

class StuffSerializer(serializers.ModelSerializer):
    numbers = IntegerRangeField(
        default=NumericRange(lower=0, upper=86400),
        required=False,
        allow_null=True,
    )

At creation time it will create a query that has a double cast '(,)'::numrange::int4range

This happens because NumericRange is casted by the psycopq transformer.

@vbabiy
Copy link
Author

vbabiy commented Oct 30, 2024

You can work around this bug by defining custom fields:

class MyIntegerRangeField(IntegerRangeField):
    range_type = Int4Range

class StuffSerializer(serializers.ModelSerializer):
    numbers = MyIntegerRangeField(
        default=Int4Range(lower=0, upper=86400),
        required=False,
        allow_null=True,
    )

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

1 participant