ema / flask-moresql Goto Github PK
View Code? Open in Web Editor NEWA thin layer of glue between PostgreSQL stored procedures and Python/Flask web applications
Home Page: http://packages.python.org/Flask-MoreSQL/
License: Other
A thin layer of glue between PostgreSQL stored procedures and Python/Flask web applications
Home Page: http://packages.python.org/Flask-MoreSQL/
License: Other
Hi there,
After a stored procedure call failure, there is a need for the session to have the transaction rolled back, but then it isn't by Flask-MoreSQL, and any further requests failed with an
InternalError: current transaction is aborted, commands ignored until end of transaction block
error, as in:
Traceback (most recent call last):
File "/home/***/dev/quote-api/flask/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/home/***/dev/quote-api/flask/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/home/***/dev/quote-api/flask/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/***/dev/quote-api/flask/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/home/***/dev/quote-api/flask/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/***/dev/quote-api/flask/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/***/dev/quote-api/flask/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/home/***/dev/quote-api/flask/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/***/dev/quote-api/flask_pg.py", line 48, in indicate
return db.execute('getIndQuote',fields=['curpairreq']);
File "/home/***/dev/quote-api/flask/lib/python2.7/site-packages/flask_moresql.py", line 130, in execute
result = self.cursor.callproc(procname, procargs)
File "/home/***/dev/quote-api/flask/lib/python2.7/site-packages/psycopg2/extras.py", line 228, in callproc
return super(RealDictCursor, self).callproc(procname, vars)
InternalError: current transaction is aborted, commands ignored until end of transaction block
-->
Good day,
After having my head broken (again) on the code, I finally found why the above won't work, typically for two or more (and not that well documented that it will or won't) but only the case of HTTP variables to be passed as URL routes/paths.
The following fails as it doesn't send any parameters to the PostgreSQL stored procedure:
@app.route('/switch/<ref>/<uuid>',methods=['GET'])
def doswitch(ref,uuid):
return db.execute('switchproc',fields=['ref','uuid'])
It's tested that in the case where I'm using variables like 'http://localhost/route?var1=value&var2=morevalue' it works fine, ie.:
@app.route('/user', methods=['GET'])
def get_user_data():
return db.execute('get_user', fields=['curpair', 'ref'])
Looking at the code, it appears to assume that we'll aways be using the variable and not the url path method, looking at line 128 of https://github.com/ema/flask-moresql/blob/master/flask_moresql.py :
procargs = _get_procedure_arguments(fields, values)
Hi there! Can you provide an SQL script (or something like that) to initialize the database used by the example.py app?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.