Opened 6 years ago

Last modified 6 years ago

#29777 closed Bug

ORA-00933: SQL command not properly ended with pagination in a ModelViewSet — at Initial Version

Reported by: DUVAL Olivier Owned by: nobody
Component: Database layer (models, ORM) Version: 2.1
Severity: Normal Keywords: orm, oracle, pagination
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

After an upgrade from Django 2.0.6 to Django 2.1.1 and DRF 3.8.2, I got an error with a ModelViewSet with pagination, it worked with previous version.

When I get rid off pagination, there is no problems.

The stack error, notice the end :

  api-dev         | The above exception was the direct cause of the following exception:
api-dev         |
api-dev         | Traceback (most recent call last):
api-dev         |   File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
api-dev         |     response = get_response(request)
api-dev         |   File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
api-dev         |     response = self.process_exception_by_middleware(e, request)
api-dev         |   File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 124, in _get_response
api-dev         |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
api-dev         |   File "/usr/local/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
api-dev         |     return view_func(*args, **kwargs)
api-dev         |   File "/usr/local/lib/python3.6/site-packages/rest_framework/viewsets.py", line 103, in view
api-dev         |     return self.dispatch(request, *args, **kwargs)
api-dev         |   File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 483, in dispatch
api-dev         |     response = self.handle_exception(exc)
api-dev         |   File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 443, in handle_exception
api-dev         |     self.raise_uncaught_exception(exc)
api-dev         |   File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 480, in dispatch
api-dev         |     response = handler(request, *args, **kwargs)
api-dev         |   File "/usr/local/lib/python3.6/site-packages/rest_framework/mixins.py", line 42, in list
api-dev         |     page = self.paginate_queryset(queryset)
api-dev         |   File "/usr/local/lib/python3.6/site-packages/rest_framework/generics.py", line 173, in paginate_queryset
api-dev         |     return self.paginator.paginate_queryset(queryset, self.request, view=self)
api-dev         |   File "/usr/local/lib/python3.6/site-packages/rest_framework/pagination.py", line 337, in paginate_queryset
api-dev         |     return list(queryset[self.offset:self.offset + self.limit])
api-dev         |   File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 268, in __iter__
api-dev         |     self._fetch_all()
api-dev         |   File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 1186, in _fetch_all
api-dev         |     self._result_cache = list(self._iterable_class(self))
api-dev         |   File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 54, in __iter__
api-dev         |     results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
api-dev         |   File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1065, in execute_sql
api-dev         |     cursor.execute(sql, params)
api-dev         |   File "/usr/local/lib/python3.6/site-packages/debug_toolbar/panels/sql/tracking.py", line 176, in execute
api-dev         |     return self._record(self.cursor.execute, sql, params)
api-dev         |   File "/usr/local/lib/python3.6/site-packages/debug_toolbar/panels/sql/tracking.py", line 117, in _record
api-dev         |     return method(sql, params)
api-dev         |   File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 100, in execute
api-dev         |     return super().execute(sql, params)
api-dev         |   File "/usr/local/lib/python3.6/site-packages/raven/contrib/django/client.py", line 127, in execute
api-dev         |     return real_execute(self, sql, params)
api-dev         |   File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
api-dev         |     return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
api-dev         |   File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
api-dev         |     return executor(sql, params, many, context)
api-dev         |   File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
api-dev         |     return self.cursor.execute(sql, params)
api-dev         |   File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
api-dev         |     raise dj_exc_value.with_traceback(traceback) from exc_value
api-dev         |   File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
api-dev         |     return self.cursor.execute(sql, params)
api-dev         |   File "/usr/local/lib/python3.6/site-packages/django/db/backends/oracle/base.py", line 513, in execute
api-dev         |     return self.cursor.execute(query, self._param_generator(params))
api-dev         | django.db.utils.DatabaseError: ORA-00933: SQL command not properly ended

Example of my ModelViewSet and Model

Code highlighting:

class MelLoginViewSet(viewsets.ModelViewSet):
    queryset = MelLoginAnglais.objects.all()
    serializer_class = MelLoginAnglaisSimpleSerializer

    filter_backends = (django_filters.rest_framework.DjangoFilterBackend, OrderingFilter, SearchFilter,)

    pagination_class = LimitOffsetPagination
    page_size = 10

class MelLoginAnglais(models.Model):
    cod_ind = models.IntegerField(primary_key=True)
    nom_login = models.CharField(max_length=100)

    def __str__(self):
        return "MelLogin : {cod} {login}".format(
            cod=self.cod_ind,
            login=self.nom_login
        )

    class Meta:
        db_table = '"APOGEE"."MEL_LOGIN"'
        managed = False

with python 3.6, Oracle 11.0.2.4

cx-Oracle 5.2.1 or 7.0

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top