When I run
heroku run python
>>> from app.main import app
>>> app.config['SQLALCHEMY_DATABASE_URI']
'postgres://<url string>' # the database url is passed correctly
>>> from app.main import db
>>> db.create_all()
it gives this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/app/.heroku/python/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 1039, in create_all
self._execute_for_all_tables(app, bind, 'create_all')
File "/app/.heroku/python/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 1031, in _execute_for_all_tables
op(bind=self.get_engine(app, bind), **extra)
File "/app/.heroku/python/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 962, in get_engine
return connector.get_engine()
File "/app/.heroku/python/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 556, in get_engine
self._engine = rv = self._sa.create_engine(sa_url, options)
File "/app/.heroku/python/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 972, in create_engine
return sqlalchemy.create_engine(sa_url, **engine_opts)
File "<string>", line 2, in create_engine
File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/util/deprecations.py", line 298, in warned
return fn(*args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/create.py", line 520, in create_engine
entrypoint = u._get_entrypoint()
File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/url.py", line 653, in _get_entrypoint
cls = registry.load(name)
File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py", line 342, in load
"Can't load plugin: %s:%s" % (self.group, name)
sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgres
I'm confused because I'm new to Heroku and Postgresql (been using SQLite until now) and none of the tutorials I'm following explain how it all connects to Flask, only how to do it. So I don't understand what to look at to fix the problem. Is there any other code I should include in the question?
(Most of the other questions like this one are typos or errors that don't fix this issue.)
This is due to a change in the sqlalchemy library. It was an announced deprecation in the changing of the dialect (the part before the ':' in the SQLALCHEMY_DATABASE_URI) name postgres to postgresql. They released this breaking change from this github commit with a minor version release, which is in their policy to do so.
Heroku's default dialect is postgres in the DATABASE_URL they provide, which gets translated into the SQLALCHEMY_DATABASE_URI. Heroku could update their postgres add-on if updating does not break other libraries which might depend on it.
In the meantime, you can pin your sqlalchemy library back to <1.4.0 (1.3.23 is the last 1.3.x release), and it should work.
Alternatively, you can update your code to modify the dialect.
Here's a quick one that works for me, with the latest PostgreSQL on Heroku:
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL').replace("://", "ql://", 1)
Just hacks the postgres:// from Heroku (which can't be edited) to postgresql://.
Related
When I run
heroku run python
>>> from app.main import app
>>> app.config['SQLALCHEMY_DATABASE_URI']
'postgres://<url string>' # the database url is passed correctly
>>> from app.main import db
>>> db.create_all()
it gives this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/app/.heroku/python/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 1039, in create_all
self._execute_for_all_tables(app, bind, 'create_all')
File "/app/.heroku/python/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 1031, in _execute_for_all_tables
op(bind=self.get_engine(app, bind), **extra)
File "/app/.heroku/python/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 962, in get_engine
return connector.get_engine()
File "/app/.heroku/python/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 556, in get_engine
self._engine = rv = self._sa.create_engine(sa_url, options)
File "/app/.heroku/python/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 972, in create_engine
return sqlalchemy.create_engine(sa_url, **engine_opts)
File "<string>", line 2, in create_engine
File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/util/deprecations.py", line 298, in warned
return fn(*args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/create.py", line 520, in create_engine
entrypoint = u._get_entrypoint()
File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/url.py", line 653, in _get_entrypoint
cls = registry.load(name)
File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py", line 342, in load
"Can't load plugin: %s:%s" % (self.group, name)
sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgres
I'm confused because I'm new to Heroku and Postgresql (been using SQLite until now) and none of the tutorials I'm following explain how it all connects to Flask, only how to do it. So I don't understand what to look at to fix the problem. Is there any other code I should include in the question?
(Most of the other questions like this one are typos or errors that don't fix this issue.)
This is due to a change in the sqlalchemy library. It was an announced deprecation in the changing of the dialect (the part before the ':' in the SQLALCHEMY_DATABASE_URI) name postgres to postgresql. They released this breaking change from this github commit with a minor version release, which is in their policy to do so.
Heroku's default dialect is postgres in the DATABASE_URL they provide, which gets translated into the SQLALCHEMY_DATABASE_URI. Heroku could update their postgres add-on if updating does not break other libraries which might depend on it.
In the meantime, you can pin your sqlalchemy library back to <1.4.0 (1.3.23 is the last 1.3.x release), and it should work.
Alternatively, you can update your code to modify the dialect.
Here's a quick one that works for me, with the latest PostgreSQL on Heroku:
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL').replace("://", "ql://", 1)
Just hacks the postgres:// from Heroku (which can't be edited) to postgresql://.
I started using Flask-Migrate today and installed it on a test project.
However i am getting following error:
alembic.util.exc.CommandError: Can't locate revision identified by
'e39d16e62810'
Steps to reproduce:
run "python create_db.py"
run "flask db init"
add column "name" to Entry-model
run "flask db migrate"
EDIT:
After removing migrations directory and repeating the process i am getting the same error after running "flask db migrate".
I also tried using a manage.py file with flask-script --> same issue
Error:
(venv_mentz) H:\Flask-API-Test>python manage.py db migrate
INFO [alembic.runtime.migration] Context impl SQLiteImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
Traceback (most recent call last):
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\alembic\script\base.py", line 143, in _catch_revision_errors
yield
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\alembic\script\base.py", line 206, in get_revisions
return self.revision_map.get_revisions(id_)
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\alembic\script\revision.py", line 299, in get_revisions
return sum([self.get_revisions(id_elem) for id_elem in id_], ())
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\alembic\script\revision.py", line 299, in <listcomp>
return sum([self.get_revisions(id_elem) for id_elem in id_], ())
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\alembic\script\revision.py", line 304, in get_revisions
for rev_id in resolved_id)
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\alembic\script\revision.py", line 304, in <genexpr>
for rev_id in resolved_id)
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\alembic\script\revision.py", line 362, in _revision_for_ident
resolved_id)
alembic.script.revision.ResolutionError: No such revision or branch 'e39d16e62810'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 14, in <module>
manager.run()
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\flask_script\__init__.py", line 417, in run
result = self.handle(argv[0], argv[1:])
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\flask_script\__init__.py", line 386, in handle
res = handle(*args, **config)
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\flask_script\commands.py", line 216, in __call__
return self.run(*args, **kwargs)
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\flask_migrate\__init__.py", line 197, in migrate
version_path=version_path, rev_id=rev_id)
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\alembic\command.py", line 176, in revision
script_directory.run_env()
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\alembic\script\base.py", line 425, in run_env
util.load_python_file(self.dir, 'env.py')
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\alembic\util\pyfiles.py", line 81, in load_python_file
module = load_module_py(module_id, path)
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\alembic\util\compat.py", line 83, in load_module_py
spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "migrations\env.py", line 87, in <module>
run_migrations_online()
File "migrations\env.py", line 80, in run_migrations_online
context.run_migrations()
File "<string>", line 8, in run_migrations
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\alembic\runtime\environment.py", line 836, in run_migrations
self.get_context().run_migrations(**kw)
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\alembic\runtime\migration.py", line 321, in run_migrations
for step in self._migrations_fn(heads, self):
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\alembic\command.py", line 156, in retrieve_migrations
revision_context.run_autogenerate(rev, context)
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\alembic\autogenerate\api.py", line 415, in run_autogenerate
self._run_environment(rev, migration_context, True)
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\alembic\autogenerate\api.py", line 425, in _run_environment
if set(self.script_directory.get_revisions(rev)) != \
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\alembic\script\base.py", line 206, in get_revisions
return self.revision_map.get_revisions(id_)
File "c:\users\marschall\appdata\local\programs\python\python36-32\Lib\contextlib.py", line 100, in __exit__
self.gen.throw(type, value, traceback)
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\alembic\script\base.py", line 174, in _catch_revision_errors
compat.raise_from_cause(util.CommandError(resolution))
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\alembic\util\compat.py", line 194, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=exc_value)
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\alembic\util\compat.py", line 187, in reraise
raise value.with_traceback(tb)
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\alembic\script\base.py", line 143, in _catch_revision_errors
yield
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\alembic\script\base.py", line 206, in get_revisions
return self.revision_map.get_revisions(id_)
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\alembic\script\revision.py", line 299, in get_revisions
return sum([self.get_revisions(id_elem) for id_elem in id_], ())
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\alembic\script\revision.py", line 299, in <listcomp>
return sum([self.get_revisions(id_elem) for id_elem in id_], ())
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\alembic\script\revision.py", line 304, in get_revisions
for rev_id in resolved_id)
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\alembic\script\revision.py", line 304, in <genexpr>
for rev_id in resolved_id)
File "H:\Flask-API-Test\venv_mentz\lib\site-packages\alembic\script\revision.py", line 362, in _revision_for_ident
resolved_id)
alembic.util.exc.CommandError: Can't locate revision identified by 'e39d16e62810'
My file structure looks like this:
app
-- views
----- __init__.py
----- main.py
-- __init__.py
-- config.py
-- models.py
instance
-- __init__.py
-- config.py
create_db.py
dev.db
run.py
My app factory:
from flask import Flask
from instance.config import app_config
from flask_migrate import Migrate
def create_app(config_name):
""" Creates a runnable app.
This app will be using the config with name "config_name".
"""
app = Flask(__name__)
# Loading the the config from instance folder with name "config_name"
app.config.from_object(app_config[config_name])
# Loading generic config from 'config.py'
app.config.from_pyfile('config.py')
# Registering this app at db
from app.models import db
db.init_app(app)
migrate = Migrate(app, db)
from app import models, views
return app
My run.py:
""" This script runs a the app with the given configuration. """
from app import create_app
# Configuration used to run the app
config_name = 'dev'
# Creating the app by using the required configuration
app = create_app(config_name)
if __name__ == '__main__':
app.run()
And my create_db.py file to create the database using models.py:
""" This script creates the database defined in app.models. """
from app import create_app
app = create_app('dev')
from app.models import db
# Telling SQLAlchemy what app should be used as the database model
with app.app_context():
db.create_all()
This is my models.py:
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class Entry(db.Model):
__tablename__ = 'Entries'
layer_id = db.Column(db.Integer, primary_key=True)
def __repr__(self):
return "ID: {}; text: {}".format(self.layer_id, self.text)
EDIT: manage.py:
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
from app import create_app
from app import models
from app.models import db
app = create_app('dev')
migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command('db', MigrateCommand)
if __name__ == '__main__':
manager.run()
you delete the migration directory but the version has been saved in the database, so you have to delete the version info in the dabase,
run
delete from alembic_version;
in mysql shell.
As suggested by #mirekphd, If this is a developing environment or a single app for test, just delete it, Else BACKUP the data in the table.
I tried this on flask and it worked:
python app.py db revision --rev-id e39d16e62810
python app.py db migrate
python app.py db upgrade
In my case I have accidentally deleted the most recent migration file but the alembic version (alembic_version) table refers to the deleted version.
So instead of droping the entire database, you can change the version_num field in the alembic_version table.
Following steps worked for me:
Find the head using db history
Update the version_num field to the head version.
run migrate using db migrate
upgrade the database db upgrade
Most of the time this happens, if you are at the development stage where you don't have much data to loose, you can drop the database and create a fresh one, alternatively, you can delete the migrations and begin the whole cycle again, for sqlite, it is all about deleting the sqlite file in your application, and beginning this cycle again. I hope to find the best solution to this verry soon.
In my case, I have accidentally deleted the most recent migration file but the alembic version (alembic_version) table refers to the deleted version.
I tried the following:
flask db revision --rev-id [revision-id]
flask db migrate
flask db upgrade
My problem was that another flask app was already connected to the same database, so I just created a new database, and changed:
SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:root#127.0.0.1:3306/newDataBaseName'
Delete the history entry from the database will solve the issue.
Error: alembic.util.exc.CommandError: Can't locate revision identified by 'e39d16e62810'
select * from alembic_version where version_num='e39d16e62810'
Option 1: Update the record with your latest revision id
update alembic_version set version_num='<your_version_num>' where version_num='e39d16e62810'
Option 2: Delete this record:
delete from alembic_version where version_num='e39d16e62810'
For my case reason for the error was the relative path to sqlite db.
Fixed it by specifying the absolute path
app.config['SQLALCHEMY_DATABASE_URI'] = f"sqlite:///{os.path.join(os.path.dirname(__file__), os.path.pardir, 'db.sqlite')}"
Yet another cause of problems - making two flask projects in the same virtual environment.
I tried to make fake twin project for performance testing.
copied crucial parts of the original project
created new database
made changes in configuration file to point to new database
flask db init,
flask db migrate
got this error at first migration.
Then I did only one thing - created new python environment for this twin project - and error disappeared.
PS. Maybe it is possible to create two flask projects in the same environment, but I was not able to find solution.
In my case, since I was in the initial phase, I had the luxury of deleting the database file directly i.e. in my project folder there was a .sqlite file, so I deleted it by right-clicking it.
But please keep in mind that I was in the initial phase, so I won't suggest this if you are
not in the starting phase.
I had the same error message but in my case it's because I used wrong database name in the connection string. Check your connection string
Error Message:
ERROR [root] Error: Can't locate revision identified by 'a80ab7ca5e1a'
Reason:
My connection string was:
mysql+pymysql://kaunda:kaunda#localhost:3306/smis
Instead of
mysql+pymysql://kaunda:kaunda#localhost:3306/WorkFolder
The revision identified by "a80ab7ca5e1a" belongs to the database "smis" not "WorkFolder"
Make sure you set FLASK_APP=app.py on windows or export FLASK_APP=app.py on MAC before running flask db init, then flask db migrate -m "message" and flask db upgrade. You can check this link for more info https://pypi.org/project/Flask-Migrate/
As the title suggests, I am seeing this error when my flask app tries to run.
I am hosting the application locally using dev_appserver.
The error occurs when I visit the site and it tries to run the app. It appears that GAE is trying and failing to bind a socket for some reason.
I suspect that this may have something to do with OAuth2. Maybe it requires an SSL connection?
I don't even know where to begin solving this as none of the other posts about this are experiencing the same variation of the issue.
Edit: Here's a screenshot of the console confirming that the GAE server launches successfully on a different port; still doesn't resolve it
Traceback (most recent call last):
File "C:\Users\XXX\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "C:\Users\XXX\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "C:\Users\XXX\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "C:\Users\XXX\PycharmProjects\ad-assignment\main.py", line 51, in <module>
app.run()
File "C:\Users\XXX\PycharmProjects\ad-assignment\lib\flask\app.py", line 843, in run
run_simple(host, port, self, **options)
File "C:\Users\XXX\PycharmProjects\ad-assignment\lib\werkzeug\serving.py", line 694, in run_simple
inner()
File "C:\Users\XXX\PycharmProjects\ad-assignment\lib\werkzeug\serving.py", line 656, in inner
fd=fd)
File "C:\Users\XXX\PycharmProjects\ad-assignment\lib\werkzeug\serving.py", line 550, in make_server
passthrough_errors, ssl_context, fd=fd)
File "C:\Users\XXX\PycharmProjects\ad-assignment\lib\werkzeug\serving.py", line 464, in __init__
HTTPServer.__init__(self, (host, int(port)), handler)
File "C:\Python27\Lib\SocketServer.py", line 417, in __init__
self.server_bind()
File "C:\Python27\Lib\BaseHTTPServer.py", line 108, in server_bind
SocketServer.TCPServer.server_bind(self)
File "C:\Python27\Lib\SocketServer.py", line 431, in server_bind
self.socket.bind(self.server_address)
File "C:\Users\XXX\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\dist27\socket.py", line 222, in meth
return getattr(self._sock,name)(*args)
File "C:\Users\XXX\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\api\remote_socket\_remote_socket.py", line 676, in bind
raise _SystemExceptionFromAppError(e)
error: [Errno 13] Permission denied
INFO 2016-12-16 21:41:51,631 module.py:788] default: "GET /oauth2callback?code=x/xxxxxxxxxxxxxxxxx HTTP/1.1" 500 -
Code (as seen in Google's OAuth2 usage guide):
import flask
app = flask.Flask(__name__)
#app.route('/')
def index():
...
#app.route('/oauth2callback')
def oauth2callback():
...
if __name__ == 'main':
import uuid
app.secret_key = str(uuid.uuid4())
app.debug = False
app.run()
We have a tutorial that walks you through adding Firebase Authentication to your Python app running with Flask. Firebase Authentication is the preferred identity toolkit now. You can of course still use a pure OAuth2 flow, but Firebase Auth also provides multi-provider authentication if that's something you were considering adding to your app anyways. If you just want to dive into the sample's code its here on GitHub.
If you just want to stick with straight OAuth, you might want to look at your Flask code itself. Getting flask to run is pretty easy on App Engine. My guess is that you're calling some code that you don't need to (flask.run()) or you aren't importing your library properly (see appengine_config.py).
I'm using Invenio 2.0 and try to replace old version of SQLAlchemy 0.8.7 with the last 0.9.7.
The utility to automaticaly create the db works (inveniomanage database recreate --yes-i-know).
But when I start tests with: python setup.py test
It return me a error:
test_fisrt_blueprint (invenio.testsuite.test_ext_template.TemplateLoaderCase) ... --------------------------------------------------------------------------------
ERROR in wrappers [/home/vagrant/.virtualenvs/invenio2/src/invenio/invenio/ext/logging/wrappers.py:310]:
--------------------------------------------------------------------------------
Traceback (most recent call last):
File "/home/vagrant/.virtualenvs/invenio2/src/invenio/invenio/ext/legacy/__init__.py", line 124, in __call__
response = self.app.full_dispatch_request()
File "/home/vagrant/.virtualenvs/invenio2/local/lib/python2.7/site-packages/flask/app.py", line 1470, in full_dispatch_request
self.try_trigger_before_first_request_functions()
File "/home/vagrant/.virtualenvs/invenio2/local/lib/python2.7/site-packages/flask/app.py", line 1497, in try_trigger_before_first_request_functions
func()
File "/home/vagrant/.virtualenvs/invenio2/src/invenio/invenio/modules/messages/views.py", line 264, in invoke_email_alert_register
email_alert_register()
File "/home/vagrant/.virtualenvs/invenio2/src/invenio/invenio/modules/messages/models.py", line 202, in email_alert_register
event.listen(MsgMESSAGE, 'after_insert', email_alert)
File "/home/vagrant/.virtualenvs/invenio2/local/lib/python2.7/site-packages/sqlalchemy/event/api.py", line 63, in listen
_event_key(target, identifier, fn).listen(*args, **kw)
File "/home/vagrant/.virtualenvs/invenio2/local/lib/python2.7/site-packages/sqlalchemy/event/registry.py", line 187, in listen
self.dispatch_target.dispatch._listen(self, *args, **kw)
File "/home/vagrant/.virtualenvs/invenio2/local/lib/python2.7/site-packages/sqlalchemy/orm/events.py", line 547, in _listen
event_key.base_listen(**kw)
File "/home/vagrant/.virtualenvs/invenio2/local/lib/python2.7/site-packages/sqlalchemy/event/registry.py", line 226, in base_listen
for_modify(target.dispatch).append(self, propagate)
File "/home/vagrant/.virtualenvs/invenio2/local/lib/python2.7/site-packages/sqlalchemy/event/attr.py", line 328, in append
event_key.append_to_list(self, self.listeners)
File "/home/vagrant/.virtualenvs/invenio2/local/lib/python2.7/site-packages/sqlalchemy/event/registry.py", line 237, in append_to_list
_stored_in_collection(self, owner)
File "/home/vagrant/.virtualenvs/invenio2/local/lib/python2.7/site-packages/sqlalchemy/event/registry.py", line 74, in _stored_in_collection
assert dispatch_reg[owner_ref] == listen_ref
AssertionError
In /home/vagrant/.virtualenvs/invenio2/src/invenio/invenio/modules/messages/views.py (row 264)
# Registration of email_alert invoked from blueprint
# in order to use before_app_first_request.
# Reading config CFG_WEBMESSAGE_EMAIL_ALERT
# required app context.
#blueprint.before_app_first_request
def invoke_email_alert_register():
email_alert_register()
In /home/vagrant/.virtualenvs/invenio2/src/invenio/invenio/modules/messages/models.py (row 202)
# Registration of email_alert invoked from blueprint
# in order to use before_app_first_request.
# Reading config CFG_WEBMESSAGE_EMAIL_ALERT
# required app context.
def email_alert_register():
if cfg['CFG_WEBMESSAGE_EMAIL_ALERT']:
from sqlalchemy import event
# Register after insert callback.
event.listen(MsgMESSAGE, 'after_insert', email_alert)
Someone can help me?
Installed:
-e git+https://github.com/mitsuhiko/flask-sqlalchemy#c7eccba63314f3ea77e2c6217d3d3c8b0d2552fd#egg=Flask_SQLAlchemy-2.0
MySQL-python==1.2.5
SQLAlchemy==0.9.7
SQLAlchemy-Utils==0.23.5
With help from google (today) I found what I suspect would be a solution here (I'm not an invenio user)
I suspect an SQLa update will fix your issue.
https://bitbucket.org/zzzeek/sqlalchemy/issue/3199/deduplication-of-events-doesnt-work-for
-->
https://bitbucket.org/zzzeek/sqlalchemy/commits/9ae4db27b993
-->
Fixed in SQLA 0.9.8 (supposedly)
I'm trying to build a webapp on Heroku using Python/Django, and I just followed the tutorial to set up a Django project and push it to Heroku. However, I can never even get to the normal Django "It worked!" screen. Of course, that is because when I check heroku ps, there are never any processes running. There is no Procfile but according to the tutorial, that shouldn't matter for a Django app.
When I run heroku run python manage.py runserver, the following error occurs:
Unhandled exception in thread started by <bound method Command.inner_run of <dja
ngo.contrib.staticfiles.management.commands.runserver.Command object at 0x1ff819
0>>
Traceback (most recent call last):
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/com
mands/runserver.py", line 91, in inner_run
self.validate(display_num_errors=True)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/bas
e.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/val
idation.py", line 103, in get_validation_errors
connection.validation.validate_field(e, opts, f)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/mysql/v
alidation.py", line 14, in validate_field
db_version = self.connection.get_server_version()
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/mysql/b
ase.py", line 411, in get_server_version
self.cursor()
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/__init_
_.py", line 306, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/mysql/b
ase.py", line 387, in _cursor
self.connection = Database.connect(**kwargs)
File "/app/.heroku/venv/lib/python2.7/site-packages/MySQLdb/__init__.py", line
81, in Connect
return Connection(*args, **kwargs)
File "/app/.heroku/venv/lib/python2.7/site-packages/MySQLdb/connections.py", l
ine 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1044, "Access denied for user '<user>
'#'%' to database 'heroku_<####################>?reconnect=true'")
I did already set my DATABASE_URL to the value of CLEARDB_DATABASE_URL. Also, in the Django settings.py, I added as instructed:
import dj_database_url
DATABASES = {'default': dj_database_url.config(default='postgres://localhost')}
Any help would be greatly appreciated.
That particular error was fixed after calling ClearDB. Turns out that the ?reconnect=true is only for Rails apps, and should be removed from the DATABASE_URL for Django apps.