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

Django and psycopg2cffi #88

Open
volvofixthis opened this issue Sep 26, 2017 · 3 comments
Open

Django and psycopg2cffi #88

volvofixthis opened this issue Sep 26, 2017 · 3 comments

Comments

@volvofixthis
Copy link

volvofixthis commented Sep 26, 2017

I have strange behaviour with django 1.11 and different versions of psycopg2cffi. Here is traceback:

Environment:

Request Method: GET
Request URL: http://testpolls.rbc.ru/v1/api/rest/user/

Django Version: 1.11
Python Version: 2.7.13
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'suit',
'debug_toolbar',
'django.contrib.admin',
'rest_framework',
'social_django',
'django_select2',
'raven.contrib.django.raven_compat',
'apps.back')
Installed Middleware:
(u'raven.contrib.django.middleware.SentryMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
'apps.back.change_http_host.ChangeHttpHost',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')

Traceback:

File "/www/polls/pypy_env/site-packages/django/core/handlers/exception.py" in inner
41. response = get_response(request)

File "/www/polls/pypy_env/site-packages/django/core/handlers/base.py" in _legacy_get_response
249. response = self._get_response(request)

File "/www/polls/pypy_env/site-packages/django/core/handlers/base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)

File "/www/polls/pypy_env/site-packages/django/core/handlers/base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/www/polls/pypy_env/site-packages/django/views/decorators/csrf.py" in wrapped_view
58. return view_func(*args, **kwargs)

File "/www/polls/pypy_env/site-packages/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)

File "/www/polls/pypy_env/site-packages/rest_framework/views.py" in dispatch
489. response = self.handle_exception(exc)

File "/www/polls/pypy_env/site-packages/rest_framework/views.py" in handle_exception
449. self.raise_uncaught_exception(exc)

File "/www/polls/pypy_env/site-packages/rest_framework/views.py" in dispatch
477. self.initial(request, *args, **kwargs)

File "/www/polls/pypy_env/site-packages/rest_framework/views.py" in initial
394. self.perform_authentication(request)

File "/www/polls/pypy_env/site-packages/rest_framework/views.py" in perform_authentication
320. request.user

File "/www/polls/pypy_env/site-packages/rest_framework/request.py" in getattribute
381. return super(Request, self).getattribute(attr)

File "/www/polls/pypy_env/site-packages/rest_framework/request.py" in user
196. self._authenticate()

File "/www/polls/pypy_env/site-packages/rest_framework/request.py" in _authenticate
345. user_auth_tuple = authenticator.authenticate(self)

File "/www/polls/pypy_env/site-packages/rest_framework/authentication.py" in authenticate
125. if not user or not user.is_active:

File "/www/polls/pypy_env/site-packages/django/utils/functional.py" in inner
238. self._setup()

File "/www/polls/pypy_env/site-packages/django/utils/functional.py" in _setup
385. self._wrapped = self._setupfunc()

File "/www/polls/pypy_env/site-packages/django/contrib/auth/middleware.py" in
24. request.user = SimpleLazyObject(lambda: get_user(request))

File "/www/polls/pypy_env/site-packages/django/contrib/auth/middleware.py" in get_user
12. request._cached_user = auth.get_user(request)

File "/www/polls/pypy_env/site-packages/django/contrib/auth/init.py" in get_user
213. user = backend.get_user(user_id)

File "/www/polls/pypy_env/site-packages/django/contrib/auth/backends.py" in get_user
102. user = UserModel._default_manager.get(pk=user_id)

File "/www/polls/pypy_env/site-packages/django/db/models/manager.py" in manager_method
85. return getattr(self.get_queryset(), name)(*args, **kwargs)

File "/www/polls/pypy_env/site-packages/django/db/models/query.py" in get
373. num = len(clone)

File "/www/polls/pypy_env/site-packages/django/db/models/query.py" in len
232. self._fetch_all()

File "/www/polls/pypy_env/site-packages/django/db/models/query.py" in _fetch_all
1102. self._result_cache = list(self._iterable_class(self))

File "/www/polls/pypy_env/site-packages/django/db/models/query.py" in iter
53. results = compiler.execute_sql(chunked_fetch=self.chunked_fetch)

File "/www/polls/pypy_env/site-packages/django/db/models/sql/compiler.py" in execute_sql
874. cursor = self.connection.cursor()

File "/www/polls/pypy_env/site-packages/debug_toolbar/panels/sql/tracking.py" in cursor
48. return state.Wrapper(connection._djdt_cursor(*args, **kwargs), connection, panel)

File "/www/polls/pypy_env/site-packages/django/db/backends/base/base.py" in cursor
254. return self._cursor()

File "/www/polls/pypy_env/site-packages/django/db/backends/base/base.py" in _cursor
229. self.ensure_connection()

File "/www/polls/pypy_env/site-packages/django/db/backends/base/base.py" in ensure_connection
213. self.connect()

File "/www/polls/pypy_env/site-packages/django/db/backends/base/base.py" in connect
190. self.set_autocommit(self.settings_dict['AUTOCOMMIT'])

File "/www/polls/pypy_env/site-packages/django/db/backends/base/base.py" in set_autocommit
411. self._set_autocommit(autocommit)

File "/www/polls/pypy_env/site-packages/django/db/backends/postgresql/base.py" in _set_autocommit
236. self.connection.autocommit = autocommit

File "/www/polls/pypy_env/site-packages/django/db/utils.py" in exit
94. six.reraise(dj_exc_type, dj_exc_value, traceback)

File "/www/polls/pypy_env/site-packages/django/db/backends/postgresql/base.py" in _set_autocommit
236. self.connection.autocommit = autocommit

File "/www/polls/pypy_env/site-packages/psycopg2cffi/_impl/connection.py" in autocommit
313. self.set_session(autocommit=value)

File "/www/polls/pypy_env/site-packages/psycopg2cffi/impl/connection.py" in check_closed
43. return func(self, *args, **kwargs)

File "/www/polls/pypy_env/site-packages/psycopg2cffi/impl/connection.py" in check_notrans
51. raise exceptions.ProgrammingError('not valid in transaction')

Exception Type: ProgrammingError at /v1/api/rest/user/
Exception Value: not valid in transaction

@volvofixthis
Copy link
Author

It was django initalization, i submitted patch already.

@lopuhin
Copy link
Member

lopuhin commented Nov 29, 2017

PR is #89, I'll need to check what psycopg2 does in this case

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
@lopuhin @volvofixthis and others