Skip to content

SqlAlchemy Model Views Break With MSSQL #582

Closed

Description

@JackStouffer

Paging on model views with MSSQL breaks because MSSQL "requires an order_by when using an offset".

2014-07-01 14:51:58,635 ERROR: Exception on /admin/screw/ [GET] [in C:\Python27\lib\site-packages\flask\app.py:1423]
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\flask\app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Python27\lib\site-packages\flask\app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Python27\lib\site-packages\flask\app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Python27\lib\site-packages\flask\app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\Python27\lib\site-packages\flask\app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "C:\Python27\lib\site-packages\flask_admin\base.py", line 62, in inner
    return f(self, *args, **kwargs)
  File "C:\Python27\lib\site-packages\flask_admin\base.py", line 62, in inner
    return f(self, *args, **kwargs)
  File "C:\Python27\lib\site-packages\flask_admin\base.py", line 62, in inner
    return f(self, *args, **kwargs)
  File "C:\Python27\lib\site-packages\flask_admin\model\base.py", line 1149, in index_view
    search, filters)
  File "C:\Python27\lib\site-packages\flask_admin\contrib\sqla\view.py", line 774, in get_list
    query = query.all()
  File "C:\Python27\lib\site-packages\sqlalchemy\orm\query.py", line 2293, in all
    return list(self)
  File "C:\Python27\lib\site-packages\sqlalchemy\orm\query.py", line 2405, in __iter__
    return self._execute_and_instances(context)
  File "C:\Python27\lib\site-packages\sqlalchemy\orm\query.py", line 2420, in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
  File "C:\Python27\lib\site-packages\sqlalchemy\engine\base.py", line 727, in execute
    return meth(self, multiparams, params)
  File "C:\Python27\lib\site-packages\sqlalchemy\sql\elements.py", line 322, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "C:\Python27\lib\site-packages\sqlalchemy\engine\base.py", line 817, in _execute_clauseelement
    inline=len(distilled_params) > 1)
  File "<string>", line 1, in <lambda>
  File "C:\Python27\lib\site-packages\sqlalchemy\sql\elements.py", line 493, in compile
    return self._compiler(dialect, bind=bind, **kw)
  File "C:\Python27\lib\site-packages\sqlalchemy\sql\elements.py", line 499, in _compiler
    return dialect.statement_compiler(dialect, self, **kw)
  File "C:\Python27\lib\site-packages\sqlalchemy\dialects\mssql\base.py", line 712, in __init__
    super(MSSQLCompiler, self).__init__(*args, **kwargs)
  File "C:\Python27\lib\site-packages\sqlalchemy\sql\compiler.py", line 390, in __init__
    Compiled.__init__(self, dialect, statement, **kwargs)
  File "C:\Python27\lib\site-packages\sqlalchemy\sql\compiler.py", line 196, in __init__
    self.string = self.process(self.statement, **compile_kwargs)
  File "C:\Python27\lib\site-packages\sqlalchemy\sql\compiler.py", line 219, in process
    return obj._compiler_dispatch(self, **kwargs)
  File "C:\Python27\lib\site-packages\sqlalchemy\sql\visitors.py", line 79, in _compiler_dispatch
    return meth(self, **kw)
  File "C:\Python27\lib\site-packages\sqlalchemy\dialects\mssql\base.py", line 774, in visit_select
    raise exc.CompileError('MSSQL requires an order_by when '
CompileError: MSSQL requires an order_by when using an offset.

Activity

  1. mrjoes commented on Jul 1, 2014

    @mrjoes
    Contributor

    Uh oh, that's interesting. I never tried Flask-Admin with MSSQL.

    Try setting column_default_sort on a ModelView instance and see if it'll help. Other DBs don't require it.

  2. JackStouffer commented on Jul 1, 2014

    @JackStouffer
    Author

    That works, thanks.

  3. locked as resolved and limited conversation to collaborators on Jul 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions