title: 'itertools._grouper' object has no attribute 'user'
body: <p>Why can't I convert the loop <code>group</code> in <code>groupby</code> as <code>list</code>? Currently, I am working on <code>Django==2.2.1</code> and when I try this <code>data = [...]</code> below into python console, it is working fine.</p>
  
  <pre><code>from itertools import groupby
  from operator import itemgetter
  
  
  @login_required
  def list(request, template_name='cart/list.html'):
      # I also try with this dummy data
      test_data = [{'total_order':1,'agent_name':'agentbeli','total_pcs':1,'total_kg':5.0},{'total_order':1,'agent_name':'agent123','total_pcs':1,'total_kg':5.0},{'total_order':1,'agent_name':'agent123','total_pcs':1,'total_kg':6.0},{'total_order':1,'agent_name':'agentbeli','total_pcs':1,'total_kg':6.0},{'total_order':1,'agent_name':'agentbeli','total_pcs':1,'total_kg':6.0},{'total_order':1,'agent_name':'agent123','total_pcs':1,'total_kg':7.0}]
  
      print(type(data)) # a list
  
      sorted_totals = sorted(test_data, key=itemgetter('total_order'))
      for agent_name, group in groupby(sorted_totals, key=lambda x: x['agent_name']):
          print(agent_name, list(group)) # I stopped here when converting the `group` as list.
  </code></pre>
  
  <p>But, I am getting an error looking like this when I try it at views in Django.</p>
  
  <p><a href="https://i.stack.imgur.com/P4aan.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P4aan.png" alt="error"></a></p>
  
  <hr>
  
  <p>I also tried it with <code>defaultdict</code></p>
  
  <pre><code>from collections import defaultdict
  
  
  @login_required
  def list(request, template_name='cart/list.html'):
  
      test_data = [{'total_order':1,'agent_name':'agentbeli','total_pcs':1,'total_kg':5.0},{'total_order':1,'agent_name':'agent123','total_pcs':1,'total_kg':5.0},{'total_order':1,'agent_name':'agent123','total_pcs':1,'total_kg':6.0},{'total_order':1,'agent_name':'agentbeli','total_pcs':1,'total_kg':6.0},{'total_order':1,'agent_name':'agentbeli','total_pcs':1,'total_kg':6.0},{'total_order':1,'agent_name':'agent123','total_pcs':1,'total_kg':7.0}]
  
      grouped = defaultdict(list)
      for data_total in test_data:
          grouped[data_total['agent_name']].append(data_total) # stoped here
  
      grouped_out = []
      for agent_name, group in grouped.items():
          total_order = 0
          total_pcs = 0
          total_kg = 0
  
          if isinstance(group, list):
              for data_total in group:
                  total_order += data_total.get('total_order')
                  total_pcs += data_total.get('total_pcs')
                  total_kg += data_total.get('total_kg')
  
              grouped_out.append({
                  'agent_name': agent_name,
                  'total_order': total_order,
                  'total_pcs': total_pcs,
                  'total_kg': total_kg
              })
  </code></pre>
  
  <p>But the error I found stoped by wrapper view. If we following the previous issue, it referenced with this <a href="https://github.com/django/django/blob/master/django/contrib/auth/decorators.py#L19" rel="nofollow noreferrer"><code>_wrapped_view</code></a></p>
  
  <p><a href="https://i.stack.imgur.com/b5zzY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/b5zzY.png" alt="error wrapper"></a></p>