Repository: inventree/InvenTree

Issue:
[BUG] Login Error
I think this is caused by #1859 @matmair 

When I try to login I get the error below.
Strangely this is happening only with PostGreSQL... (SQLite does not show this error)

![image](https://user-images.githubusercontent.com/4020546/127020061-ca5fec2c-26c4-447a-8e38-002e260d64ed.png)

Traceback:

``` bash
The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/core/handlers/base.py", line 204, in _get_response
    response = response.render()
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/template/response.py", line 105, in render
    self.content = self.rendered_content
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/template/response.py", line 83, in rendered_content
    return template.render(context, self._request)
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/template/base.py", line 170, in render
    return self._render(context)
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/template/base.py", line 162, in _render
    return self.nodelist.render(context)
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/template/loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/template/base.py", line 162, in _render
    return self.nodelist.render(context)
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/template/library.py", line 192, in render
    output = self.func(*resolved_args, **resolved_kwargs)
  File "/home/francois/Desktop/github/InvenTree/InvenTree/part/templatetags/inventree_extras.py", line 206, in settings_value
    return InvenTreeUserSetting.get_setting(key, user=kwargs['user'])
  File "/home/francois/Desktop/github/InvenTree/InvenTree/common/models.py", line 207, in get_setting
    setting = cls.get_setting_object(key, **kwargs)
  File "/home/francois/Desktop/github/InvenTree/InvenTree/common/models.py", line 886, in get_setting_object
    return super().get_setting_object(key, user=user)
  File "/home/francois/Desktop/github/InvenTree/InvenTree/common/models.py", line 160, in get_setting_object
    setting = cls.objects.filter(**cls.get_filters(key, **kwargs)).first()
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/db/models/query.py", line 674, in first
    for obj in (self if self.ordered else self.order_by('pk'))[:1]:
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/db/models/query.py", line 280, in __iter__
    self._fetch_all()
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/db/models/query.py", line 1324, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/db/models/query.py", line 51, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1175, in execute_sql
    cursor.execute(sql, params)
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/db/backends/utils.py", line 98, in execute
    return super().execute(sql, params)
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/francois/Desktop/github/InvenTree/env-inventree/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: function upper(integer) does not exist
LINE 1: ...("common_inventreeusersetting"."user_id"::text) = UPPER(1)) ...
                                                             ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

```


Discussion:

Resolving patch:
diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py
--- a/InvenTree/common/models.py
+++ b/InvenTree/common/models.py
@@ -890,7 +890,7 @@ def validate_unique(self, exclude=None):
 
     @classmethod
     def get_filters(cls, key, **kwargs):
-        return {'key__iexact': key, 'user__id__iexact': kwargs['user'].id}
+        return {'key__iexact': key, 'user__id': kwargs['user'].id}
 
 
 class PriceBreak(models.Model):


Test patch: