mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-21 11:08:44 -06:00
Fixes #21166: Fix support for filtering on unsigned 32-bit integer values in GraphQL API
This commit is contained in:
@@ -20,7 +20,7 @@ from tenancy.graphql.filter_mixins import ContactFilterMixin, TenancyFilterMixin
|
|||||||
from virtualization.models import VMInterface
|
from virtualization.models import VMInterface
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from netbox.graphql.filter_lookups import IntegerLookup, IntegerRangeArrayLookup
|
from netbox.graphql.filter_lookups import BigIntegerLookup, IntegerLookup, IntegerRangeArrayLookup
|
||||||
from circuits.graphql.filters import ProviderFilter
|
from circuits.graphql.filters import ProviderFilter
|
||||||
from core.graphql.filters import ContentTypeFilter
|
from core.graphql.filters import ContentTypeFilter
|
||||||
from dcim.graphql.filters import SiteFilter
|
from dcim.graphql.filters import SiteFilter
|
||||||
@@ -53,7 +53,7 @@ __all__ = (
|
|||||||
class ASNFilter(TenancyFilterMixin, PrimaryModelFilter):
|
class ASNFilter(TenancyFilterMixin, PrimaryModelFilter):
|
||||||
rir: Annotated['RIRFilter', strawberry.lazy('ipam.graphql.filters')] | None = strawberry_django.filter_field()
|
rir: Annotated['RIRFilter', strawberry.lazy('ipam.graphql.filters')] | None = strawberry_django.filter_field()
|
||||||
rir_id: ID | None = strawberry_django.filter_field()
|
rir_id: ID | None = strawberry_django.filter_field()
|
||||||
asn: Annotated['IntegerLookup', strawberry.lazy('netbox.graphql.filter_lookups')] | None = (
|
asn: Annotated['BigIntegerLookup', strawberry.lazy('netbox.graphql.filter_lookups')] | None = (
|
||||||
strawberry_django.filter_field()
|
strawberry_django.filter_field()
|
||||||
)
|
)
|
||||||
sites: (
|
sites: (
|
||||||
@@ -70,10 +70,10 @@ class ASNRangeFilter(TenancyFilterMixin, OrganizationalModelFilter):
|
|||||||
slug: FilterLookup[str] | None = strawberry_django.filter_field()
|
slug: FilterLookup[str] | None = strawberry_django.filter_field()
|
||||||
rir: Annotated['RIRFilter', strawberry.lazy('ipam.graphql.filters')] | None = strawberry_django.filter_field()
|
rir: Annotated['RIRFilter', strawberry.lazy('ipam.graphql.filters')] | None = strawberry_django.filter_field()
|
||||||
rir_id: ID | None = strawberry_django.filter_field()
|
rir_id: ID | None = strawberry_django.filter_field()
|
||||||
start: Annotated['IntegerLookup', strawberry.lazy('netbox.graphql.filter_lookups')] | None = (
|
start: Annotated['BigIntegerLookup', strawberry.lazy('netbox.graphql.filter_lookups')] | None = (
|
||||||
strawberry_django.filter_field()
|
strawberry_django.filter_field()
|
||||||
)
|
)
|
||||||
end: Annotated['IntegerLookup', strawberry.lazy('netbox.graphql.filter_lookups')] | None = (
|
end: Annotated['BigIntegerLookup', strawberry.lazy('netbox.graphql.filter_lookups')] | None = (
|
||||||
strawberry_django.filter_field()
|
strawberry_django.filter_field()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -19,8 +19,11 @@ from strawberry_django import (
|
|||||||
process_filters,
|
process_filters,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from netbox.graphql.scalars import BigInt
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'ArrayLookup',
|
'ArrayLookup',
|
||||||
|
'BigIntegerLookup',
|
||||||
'FloatArrayLookup',
|
'FloatArrayLookup',
|
||||||
'FloatLookup',
|
'FloatLookup',
|
||||||
'IntegerArrayLookup',
|
'IntegerArrayLookup',
|
||||||
@@ -78,6 +81,29 @@ class IntegerLookup:
|
|||||||
return process_filters(filters=filters, queryset=queryset, info=info, prefix=prefix)
|
return process_filters(filters=filters, queryset=queryset, info=info, prefix=prefix)
|
||||||
|
|
||||||
|
|
||||||
|
@strawberry.input(one_of=True, description='Lookup for BigInteger fields. Only one of the lookup fields can be set.')
|
||||||
|
class BigIntegerLookup:
|
||||||
|
filter_lookup: FilterLookup[BigInt] | None = strawberry_django.filter_field()
|
||||||
|
range_lookup: RangeLookup[BigInt] | None = strawberry_django.filter_field()
|
||||||
|
comparison_lookup: ComparisonFilterLookup[BigInt] | None = strawberry_django.filter_field()
|
||||||
|
|
||||||
|
def get_filter(self):
|
||||||
|
for field in self.__strawberry_definition__.fields:
|
||||||
|
value = getattr(self, field.name, None)
|
||||||
|
if value is not strawberry.UNSET:
|
||||||
|
return value
|
||||||
|
return None
|
||||||
|
|
||||||
|
@strawberry_django.filter_field
|
||||||
|
def filter(self, info: Info, queryset: QuerySet, prefix: DirectiveValue[str] = '') -> Tuple[QuerySet, Q]:
|
||||||
|
filters = self.get_filter()
|
||||||
|
|
||||||
|
if not filters:
|
||||||
|
return queryset, Q()
|
||||||
|
|
||||||
|
return process_filters(filters=filters, queryset=queryset, info=info, prefix=prefix)
|
||||||
|
|
||||||
|
|
||||||
@strawberry.input(one_of=True, description='Lookup for Float fields. Only one of the lookup fields can be set.')
|
@strawberry.input(one_of=True, description='Lookup for Float fields. Only one of the lookup fields can be set.')
|
||||||
class FloatLookup:
|
class FloatLookup:
|
||||||
filter_lookup: FilterLookup[float] | None = strawberry_django.filter_field()
|
filter_lookup: FilterLookup[float] | None = strawberry_django.filter_field()
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ from vpn import models
|
|||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from core.graphql.filters import ContentTypeFilter
|
from core.graphql.filters import ContentTypeFilter
|
||||||
from ipam.graphql.filters import IPAddressFilter, RouteTargetFilter
|
from ipam.graphql.filters import IPAddressFilter, RouteTargetFilter
|
||||||
from netbox.graphql.filter_lookups import IntegerLookup
|
from netbox.graphql.filter_lookups import BigIntegerLookup, IntegerLookup
|
||||||
from .enums import *
|
from .enums import *
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
@@ -187,7 +187,7 @@ class L2VPNFilter(ContactFilterMixin, TenancyFilterMixin, PrimaryModelFilter):
|
|||||||
type: BaseFilterLookup[Annotated['L2VPNTypeEnum', strawberry.lazy('vpn.graphql.enums')]] | None = (
|
type: BaseFilterLookup[Annotated['L2VPNTypeEnum', strawberry.lazy('vpn.graphql.enums')]] | None = (
|
||||||
strawberry_django.filter_field()
|
strawberry_django.filter_field()
|
||||||
)
|
)
|
||||||
identifier: Annotated['IntegerLookup', strawberry.lazy('netbox.graphql.filter_lookups')] | None = (
|
identifier: Annotated['BigIntegerLookup', strawberry.lazy('netbox.graphql.filter_lookups')] | None = (
|
||||||
strawberry_django.filter_field()
|
strawberry_django.filter_field()
|
||||||
)
|
)
|
||||||
import_targets: Annotated['RouteTargetFilter', strawberry.lazy('ipam.graphql.filters')] | None = (
|
import_targets: Annotated['RouteTargetFilter', strawberry.lazy('ipam.graphql.filters')] | None = (
|
||||||
|
|||||||
Reference in New Issue
Block a user