Changes between Initial Version and Version 1 of Ticket #30769


Ignore:
Timestamp:
Sep 10, 2019, 10:22:25 AM (5 years ago)
Author:
Tim Kleinschmidt
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #30769 – Description

    initial v1  
    6969Code which leads to the error
    7070{{{
    71         # Base Query Construct
    72         auth_query = UserAuth.objects.filter(user_id=OuterRef('user_id')).order_by(
    73             '-received_at')[:1]
    74         base_employees = (
    75             base_employees.annotate(auth_received_at=Subquery(auth_query.values('received_at')),
    76                                     auth_response=Subquery(auth_query.values('response'))))
     71# Base Query Construct
     72auth_query = UserAuth.objects.filter(user_id=OuterRef('user_id')).order_by(
     73    '-received_at')[:1]
     74base_employees = (
     75    base_employees.annotate(auth_received_at=Subquery(auth_query.values('received_at')),
     76                            auth_response=Subquery(auth_query.values('response'))))
    7777
    78      # Q object building
    79      q  = Q()
    80      if IS_AUTH_REJECTED in auth_status:
    81         q |= Q(auth_response__REJECTED='N')
     78
     79# Q object building
     80q = Q()
     81if IS_AUTH_REJECTED in auth_status:
     82    q |= Q(auth_response__REJECTED='N')
    8283
    8384base_employees.filter(q)
     
    8687Workaround
    8788{{{
    88        # base query construct
    89         auth_query = UserAuth.objects.annotate(
    90             has_access=KeyTextTransform('REJECTED', 'response')
    91         ).filter(user_id=OuterRef('user_id')).order_by('-received_at')[:1]
     89# base query construct
     90auth_query = UserAuth.objects.annotate(
     91    has_access=KeyTextTransform('REJECTED', 'response')
     92).filter(user_id=OuterRef('user_id')).order_by('-received_at')[:1]
    9293
    93         base_employees = base_employees.annotate(
    94             auth_received_at=Subquery(auth_query.values('received_at')),
    95             has_access=Subquery(auth_query.values('has_access'), output_field=CharField()))
     94base_employees = base_employees.annotate(
     95    auth_received_at=Subquery(auth_query.values('received_at')),
     96    has_access=Subquery(auth_query.values('has_access'), output_field=CharField()))
    9697
    97      # q object creation
    98      q = Q()
    99      if IS_AUTH_REJECTED in auth_status:
    100         q |= Q(has_access='N')
     98# q object creation
     99q = Q()
     100if IS_AUTH_REJECTED in auth_status:
     101    q |= Q(has_access='N')
    101102
    102     base_employees.filter(q)
     103base_employees.filter(q)
    103104
    104105}}}
Back to Top