librelist archives

« back to archive

Regarding an issue with flask SQLAlchemy.

Regarding an issue with flask SQLAlchemy.

From:
Mmn
Date:
2012-05-05 @ 17:34
Hello Folks,

I have a class called User which is subclassed as Customer/Operator etc.
When I try this query in my flask application
user = db.session.query('User').filter(User.id==1).one()
I get the exception mentioned below.

However when I create a python env and try I am able to see the Customer
object which is represented.
>>> db.session.query(User).filter(User.id == 1).one()
<justmeds.models.Customer object at 0x10253cf50>

The exception I get is
Traceback (most recent call last):
  File
"/Library/Python/2.6/site-packages/Flask-0.8-py2.6.egg/flask/app.py", line
1518, in __call__
    return self.wsgi_app(environ, start_response)
  File
"/Library/Python/2.6/site-packages/Flask-0.8-py2.6.egg/flask/app.py", line
1506, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File
"/Library/Python/2.6/site-packages/Flask-0.8-py2.6.egg/flask/app.py", line
1504, in wsgi_app
    response = self.full_dispatch_request()
  File
"/Library/Python/2.6/site-packages/Flask-0.8-py2.6.egg/flask/app.py", line
1264, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File
"/Library/Python/2.6/site-packages/Flask-0.8-py2.6.egg/flask/app.py", line
1262, in full_dispatch_request
    rv = self.dispatch_request()
  File
"/Library/Python/2.6/site-packages/Flask-0.8-py2.6.egg/flask/app.py", line
1248, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/manojmn/Desktop/justmeds/justmeds/customer_blueprint.py",
line 18, in home
    user = db.session.query('User').filter(User.id==1).one()
  File

"/Library/Python/2.6/site-packages/SQLAlchemy-0.7.1-py2.6-macosx-10.6-universal.egg/sqlalchemy/orm/query.py",
line 1744, in one
    ret = list(self)
  File

"/Library/Python/2.6/site-packages/SQLAlchemy-0.7.1-py2.6-macosx-10.6-universal.egg/sqlalchemy/orm/query.py",
line 1787, in __iter__
    return self._execute_and_instances(context)
  File

"/Library/Python/2.6/site-packages/SQLAlchemy-0.7.1-py2.6-macosx-10.6-universal.egg/sqlalchemy/orm/query.py",
line 1802, in _execute_and_
instances
    result = conn.execute(querycontext.statement, self._params)
  File

"/Library/Python/2.6/site-packages/SQLAlchemy-0.7.1-py2.6-macosx-10.6-universal.egg/sqlalchemy/engine/base.py",
line 1358, in execute
    params)
  File

"/Library/Python/2.6/site-packages/SQLAlchemy-0.7.1-py2.6-macosx-10.6-universal.egg/sqlalchemy/engine/base.py",
line 1491, in _execute_cl
auseelement
    compiled_sql, distilled_params
  File

"/Library/Python/2.6/site-packages/SQLAlchemy-0.7.1-py2.6-macosx-10.6-universal.egg/sqlalchemy/engine/base.py",
line 1599, in _execute_co
ntext
    context)
  File

"/Library/Python/2.6/site-packages/SQLAlchemy-0.7.1-py2.6-macosx-10.6-universal.egg/sqlalchemy/engine/base.py",
line 1592, in _execute_co
ntext
    context)
  File

"/Library/Python/2.6/site-packages/SQLAlchemy-0.7.1-py2.6-macosx-10.6-universal.egg/sqlalchemy/engine/default.py",
line 325, in do_execut
e
    cursor.execute(statement, parameters)
OperationalError: (OperationalError) no such column: User u'SELECT User
\nFROM user \nWHERE user.id = ?' (1,)

Can someone please help me?

Regards,
-- 
--
It’'s a fact, taller people sleep longer in bed.

Re: [flask] Regarding an issue with flask SQLAlchemy.

From:
Paul Gibbs
Date:
2012-05-05 @ 18:18
You have 'User' in quotes in the code from your application and you use 
the User object directly from the command line.  Once you get rid of the 
quotes it should work for you.

On Saturday, May 5, 2012 at 10:34 AM, MMN wrote:

> Hello Folks,
>  
> I have a class called User which is subclassed as Customer/Operator etc.
When I try this query in my flask application  
> user = db.session.query('User').filter(User.id==1).one()
> I get the exception mentioned below.
>  
> However when I create a python env and try I am able to see the Customer
object which is represented.
> >>> db.session.query(User).filter(User.id == 1).one()
> <justmeds.models.Customer object at 0x10253cf50>
>  
> The exception I get is
> Traceback (most recent call last):
>   File 
"/Library/Python/2.6/site-packages/Flask-0.8-py2.6.egg/flask/app.py", line
1518, in __call__
>     return self.wsgi_app(environ, start_response)
>   File 
"/Library/Python/2.6/site-packages/Flask-0.8-py2.6.egg/flask/app.py", line
1506, in wsgi_app
>     response = self.make_response(self.handle_exception(e))
>   File 
"/Library/Python/2.6/site-packages/Flask-0.8-py2.6.egg/flask/app.py", line
1504, in wsgi_app
>     response = self.full_dispatch_request()
>   File 
"/Library/Python/2.6/site-packages/Flask-0.8-py2.6.egg/flask/app.py", line
1264, in full_dispatch_request
>     rv = self.handle_user_exception(e)
>   File 
"/Library/Python/2.6/site-packages/Flask-0.8-py2.6.egg/flask/app.py", line
1262, in full_dispatch_request
>     rv = self.dispatch_request()
>   File 
"/Library/Python/2.6/site-packages/Flask-0.8-py2.6.egg/flask/app.py", line
1248, in dispatch_request
>     return self.view_functions[rule.endpoint](**req.view_args)
>   File "/Users/manojmn/Desktop/justmeds/justmeds/customer_blueprint.py",
line 18, in home
>     user = db.session.query('User').filter(User.id==1).one()
>   File 
"/Library/Python/2.6/site-packages/SQLAlchemy-0.7.1-py2.6-macosx-10.6-universal.egg/sqlalchemy/orm/query.py",
line 1744, in one
>     ret = list(self)
>   File 
"/Library/Python/2.6/site-packages/SQLAlchemy-0.7.1-py2.6-macosx-10.6-universal.egg/sqlalchemy/orm/query.py",
line 1787, in __iter__
>     return self._execute_and_instances(context)
>   File 
"/Library/Python/2.6/site-packages/SQLAlchemy-0.7.1-py2.6-macosx-10.6-universal.egg/sqlalchemy/orm/query.py",
line 1802, in _execute_and_
> instances
>     result = conn.execute(querycontext.statement, self._params)
>   File 
"/Library/Python/2.6/site-packages/SQLAlchemy-0.7.1-py2.6-macosx-10.6-universal.egg/sqlalchemy/engine/base.py",
line 1358, in execute
>     params)
>   File 
"/Library/Python/2.6/site-packages/SQLAlchemy-0.7.1-py2.6-macosx-10.6-universal.egg/sqlalchemy/engine/base.py",
line 1491, in _execute_cl
> auseelement
>     compiled_sql, distilled_params
>   File 
"/Library/Python/2.6/site-packages/SQLAlchemy-0.7.1-py2.6-macosx-10.6-universal.egg/sqlalchemy/engine/base.py",
line 1599, in _execute_co
> ntext
>     context)
>   File 
"/Library/Python/2.6/site-packages/SQLAlchemy-0.7.1-py2.6-macosx-10.6-universal.egg/sqlalchemy/engine/base.py",
line 1592, in _execute_co
> ntext
>     context)
>   File 
"/Library/Python/2.6/site-packages/SQLAlchemy-0.7.1-py2.6-macosx-10.6-universal.egg/sqlalchemy/engine/default.py",
line 325, in do_execut
> e
>     cursor.execute(statement, parameters)
> OperationalError: (OperationalError) no such column: User u'SELECT User 
\nFROM user \nWHERE user.id (http://user.id) = ?' (1,)
>  
> Can someone please help me?
>  
> Regards,
> --  
> --
> It’'s a fact, taller people sleep longer in bed.