Comments (9)
It's the "USE" statement (line 148, in sqlalchemy_backend.py). Postgres always connects to a database using the connect string, so the USE is not needed. A possible fix would be to change the "if" statement that checks for ":memory:" to check to see if it is postgres as well.
from bottle-cork.
To implement this properly, it should be broken out into its own class instead of the inline postgres-specific code, but for those that need it, this is my Postgres workaround. I wrote some unit tests, and it seems to work for Postgresql. As a warning, I did NOT test this thoroughly with other database types to make sure I didn't break anything.
if initialize:
# Create new database if needed.
db_url, db_name = db_full_url.rsplit('/', 1)
isPostgres = False
# Postgresql needs to be treated differently because it always
# connects to a database ... template1 is used as a dummy db
# in order to create the db we want
if db_url.startswith('postgresql'):
isPostgres = True
db_url += '/template1'
self._engine = create_engine(db_url)
# Postgresql won't let you create a database in a transaction
if isPostgres:
self._engine.raw_connection().set_isolation_level(0)
try:
self._engine.execute("CREATE DATABASE %s" % db_name)
except Exception, e:
log.info("Failed DB creation: %s" % e)
# Postgresql doesn't use the USE statement, but make
# sure you set it back to using translations
if isPostgres:
self._engine.raw_connection().set_isolation_level(1)
# SQLite in-memory database URL: "sqlite://:memory:"
elif db_name != ':memory:':
self._engine.execute("USE %s" % db_name)
else:
self._engine = create_engine(db_full_url)
from bottle-cork.
Whipped up some commits based on the above, let me know what you think: astubbs@ee6da49
from bottle-cork.
The tests don't seem to be self contained in tox. What's the process for getting this tested properly?
from bottle-cork.
Ignore that sha, the branch is here: https://github.com/astubbs/bottle-cork/tree/postgres-fix
from bottle-cork.
I didn't test it, but your branch doesn't look quite right. You are calling create_engine twice for postgresql and not setting the isolation level back. It looks like a copy-paste mistake.
from bottle-cork.
No, I added it on purpose. How can you create the database, and connect to it - I understood you have to connect directly to the db, so you'd need to reconnect, no?
But yes you were right about turning the transactions back on, I've put that back in.
Do you know if the tests should all pass in origin/master by just simply running tox?
commits: https://github.com/astubbs/bottle-cork/commits/postgres-fix
from bottle-cork.
I see what you did now, sorry about that. As far as the tests, I'm not sure. As you can guess since I posted this a while ago, I didn't get around to actually implementing it and figuring out the tests. Maybe Federico can help with some direction on running the tests.
from bottle-cork.
Hi.
I wanted to know what is the status of this issue? Was it fixed/merged? I see there is some fix on it.
Thx.
from bottle-cork.
Related Issues (20)
- MySQL server has gone away HOT 2
- SQLiteBackend.Table.iteritems() yields wrong data HOT 2
- Doco links to dead-ish downloads page on Github
- Best way to add more user fields to user profile? HOT 1
- Registration email fails if TEMPLATE_PATH is not /views/ HOT 2
- Login timeout too short HOT 1
- make doc error HOT 1
- Subclassing User HOT 2
- Security issue? problematic defaults for hashlib.pbkdf2_hmac HOT 1
- Registration does not check pending_registrations collection for existence of the user name HOT 4
- http://cork.firelet.net/ is down HOT 1
- Missing logging for auditing HOT 5
- pip update? HOT 1
- Documentation website is down HOT 1
- mongo backend doesn't work with mongdb 3.4
- Email Not Sent - Auth Error HOT 6
- TypeError @ _setup_cookie when signing/logging in HOT 1
- Docs not accessible
- Question ? Cork without beaker
- There's an error when installing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bottle-cork.