Skip to content

Commit

Permalink
Merge pull request #242 from yezyilomo/fix_ignoring_query_and_parsed_…
Browse files Browse the repository at this point in the history
…query_kwargs

Fix ignoring query & parsed_query kwargs
  • Loading branch information
yezyilomo authored Jun 1, 2021
2 parents 36f8940 + 1c54041 commit 0d2d372
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions django_restql/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def __init__(self, *args, **kwargs):
assert not(is_query_kwarg_set and is_parsed_query_kwarg_set), msg

# flag to toggle using restql fields
self._use_restql_fields = False
self._ready_to_use_dynamic_fields = False

# initialize parsed restql query
self.parsed_restql_query = None
Expand All @@ -143,7 +143,7 @@ def __init__(self, *args, **kwargs):

def to_representation(self, instance):
# Activate using restql fields
self._use_restql_fields = True
self._ready_to_use_dynamic_fields = True

if self.restql_kwargs["return_pk"]:
return instance.pk
Expand Down Expand Up @@ -360,16 +360,6 @@ def intersection(lst1, lst2):

@cached_property
def restql_fields(self):
request = self.context.get('request')

is_not_a_request_to_process = (
self.restql_kwargs["disable_dynamic_fields"] or
not (request is None or self.has_restql_query_param(request))
)

if is_not_a_request_to_process:
return self.allowed_fields

is_top_retrieve_request = (
self.field_name is None and
self.parent is None
Expand Down Expand Up @@ -419,20 +409,24 @@ def get_parsed_restql_query_from_query_kwarg(self):
return parser.parse(self.restql_kwargs["query"])

def get_parsed_restql_query(self):
request = self.context.get('request')

if self.restql_kwargs["query"] is not None:
# Get from query kwarg
return self.get_parsed_restql_query_from_query_kwarg()
elif self.restql_kwargs["parsed_query"] is not None:
# Get from parsed_query kwarg
return self.restql_kwargs["parsed_query"]
# Get from request query parameter
request = self.context.get('request', None)
return self.get_parsed_restql_query_from_req(request)
elif request is not None and self.has_restql_query_param(request):
# Get from request query parameter
return self.get_parsed_restql_query_from_req(request)
return None # There is no query so we return None as a parsed query

@property
def fields(self):
if self._use_restql_fields:
# Use restql fields
dynamic_fields_disabled = self.restql_kwargs["disable_dynamic_fields"]
if self._ready_to_use_dynamic_fields and not dynamic_fields_disabled:
# Return restql fields
return self.restql_fields
return self.allowed_fields

Expand Down

0 comments on commit 0d2d372

Please sign in to comment.