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

Crash TypeError: unhashable type: 'list' for view-only users #331

Closed
phihag opened this issue Jan 25, 2021 · 2 comments
Closed

Crash TypeError: unhashable type: 'list' for view-only users #331

phihag opened this issue Jan 25, 2021 · 2 comments

Comments

@phihag
Copy link

phihag commented Jan 25, 2021

If a user without change permissions but with view permissions visits a change page with a CountryField, it crashes:

Traceback (most recent call last):                                                                                                                                          
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner                            
    response = get_response(request)                                                                                                                                        
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/core/handlers/base.py", line 145, in _get_response                        
    response = self.process_exception_by_middleware(e, request)                                                                                                             
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/core/handlers/base.py", line 143, in _get_response                        
    response = response.render()                                                                                                                                            
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/response.py", line 106, in render                                
    self.content = self.rendered_content                                                                                                                                    
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/response.py", line 83, in rendered_content                       
    content = template.render(context, self._request)                                                                                                                       
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/backends/django.py", line 61, in render                          
    return self.template.render(context)                                                                                                                                    
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/base.py", line 171, in render                                    
    return self._render(context)                                                                                                                                            
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/test/utils.py", line 96, in instrumented_test_render                      
    return self.nodelist.render(context)                                                                                                                                    
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/base.py", line 937, in render                                    
    bit = node.render_annotated(context)                                                                                                                                    
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/base.py", line 904, in render_annotated                          
    return self.render(context)                                                                                                                                             
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/loader_tags.py", line 150, in render                             
    return compiled_parent._render(context)                                                                                                                                 
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/test/utils.py", line 96, in instrumented_test_render                      
    return self.nodelist.render(context)                                                                                                                                    
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/base.py", line 937, in render                                    
    bit = node.render_annotated(context)                                                                                                                                    
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/base.py", line 904, in render_annotated                          
    return self.render(context)                                                                                                                                             
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/loader_tags.py", line 150, in render                             
    return compiled_parent._render(context)                                                                                                                                 
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/test/utils.py", line 96, in instrumented_test_render                      
    return self.nodelist.render(context)                                                                                                                                    
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/base.py", line 937, in render                                    
    bit = node.render_annotated(context)                                                                                                                                    
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/base.py", line 904, in render_annotated                          
    return self.render(context)                                                                                                                                             
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/loader_tags.py", line 62, in render                              
    result = block.nodelist.render(context)                                                                                                                                 
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/base.py", line 937, in render                                    
    bit = node.render_annotated(context)                                                                                                                                    
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/base.py", line 904, in render_annotated                          
    return self.render(context)                                                                                                                                             
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/loader_tags.py", line 62, in render                              
    result = block.nodelist.render(context)                                                                                                                                 
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/base.py", line 937, in render                                    
    bit = node.render_annotated(context)                                                                                                                                    
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/base.py", line 904, in render_annotated                          
    return self.render(context)                                                                                                                                             
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/defaulttags.py", line 209, in render                             
    nodelist.append(node.render_annotated(context))                                                                                                                         
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/base.py", line 904, in render_annotated                          
    return self.render(context)                                                                                                                                             
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/loader_tags.py", line 188, in render                             
    return template.render(context)                                                                                                                                         
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/base.py", line 173, in render                                    
    return self._render(context)                                                                                                                                            
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/test/utils.py", line 96, in instrumented_test_render                      
    return self.nodelist.render(context)                                                                                                                                    
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/base.py", line 937, in render                                    
    bit = node.render_annotated(context)                                                                                                                                    
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/base.py", line 904, in render_annotated                          
    return self.render(context)                                                                                                                                             
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/defaulttags.py", line 209, in render                             
    nodelist.append(node.render_annotated(context))                                                                                                                         
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/base.py", line 904, in render_annotated                          
    return self.render(context)                                                                                                                                             
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/defaulttags.py", line 209, in render                             
    nodelist.append(node.render_annotated(context))                                                                                                                         
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/base.py", line 904, in render_annotated                          
    return self.render(context)                                                                                                                                             
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/defaulttags.py", line 209, in render                             
    nodelist.append(node.render_annotated(context))                                                                                                                         
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/base.py", line 904, in render_annotated                          
    return self.render(context)                                                                                                                                             
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/defaulttags.py", line 209, in render                             
    nodelist.append(node.render_annotated(context))                                                                                                                         
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/base.py", line 904, in render_annotated                          
    return self.render(context)                                                                                                                                             
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/defaulttags.py", line 309, in render                             
    return nodelist.render(context)                                                                                                                                         
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/base.py", line 937, in render
    bit = node.render_annotated(context)
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/base.py", line 904, in render_annotated
    return self.render(context)
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/defaulttags.py", line 309, in render
    return nodelist.render(context)
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/base.py", line 937, in render
    bit = node.render_annotated(context)
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/base.py", line 904, in render_annotated
    return self.render(context)
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/base.py", line 987, in render
    output = self.filter_expression.resolve(context)
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/base.py", line 671, in resolve
    obj = self.var.resolve(context)
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/base.py", line 796, in resolve
    value = self._resolve_lookup(context)
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/template/base.py", line 858, in _resolve_lookup
    current = current()
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/contrib/admin/helpers.py", line 218, in contents
    result_repr = display_for_field(value, f, self.empty_value_display)
  File "/home/phihag/.local/share/virtualenvs/octonie-vqgHbSx7/lib/python3.8/site-packages/django/contrib/admin/utils.py", line 382, in display_for_field
    return dict(field.flatchoices).get(value, empty_value_display)
TypeError: unhashable type: 'list'

The problem is that value is something like [Country(code='BE'), Country(code='CA')]. I'm not sure this can be solved in plain Django, because the render path does not seem to have a read-only rendering. See also https://code.djangoproject.com/ticket/30577

@jedie
Copy link
Contributor

jedie commented Feb 23, 2021

It's the same as #311 isn't it?

@SmileyChris
Copy link
Owner

Yeah, duplicate.

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

3 participants