Hello,
I get an error I don't really understand. When I do session commit after a deletion like this: App: app.bootstrap_new [debug] Instance: /Users/hugo/Dropbox/lahey/api/instance >>> from app.extensions import db >>> from app.models.user import User >>> user = User.query.all()[0] >>> db.session.delete(user) >>> db.session.commit() (this is in a shell with flask app context but I get the same error when trying to delete in app that is being served) > Traceback (most recent call last): > File "<console>", line 1, in <module> > File > "/Users/hugo/Dropbox/lahey/api/.venv/lib/python3.6/site-packages/sqlalchemy/orm/scoping.py", > > line 153, in do > return getattr(self.registry(), name)(*args, **kwargs) > File > "/Users/hugo/Dropbox/lahey/api/.venv/lib/python3.6/site-packages/sqlalchemy/orm/session.py", > > line 937, in commit > self.transaction.commit() > File > "/Users/hugo/Dropbox/lahey/api/.venv/lib/python3.6/site-packages/sqlalchemy/orm/session.py", > > line 461, in commit > self._prepare_impl() > File > "/Users/hugo/Dropbox/lahey/api/.venv/lib/python3.6/site-packages/sqlalchemy/orm/session.py", > > line 441, in _prepare_impl > self.session.flush() > File > "/Users/hugo/Dropbox/lahey/api/.venv/lib/python3.6/site-packages/sqlalchemy/orm/session.py", > > line 2237, in flush > self._flush(objects) > File > "/Users/hugo/Dropbox/lahey/api/.venv/lib/python3.6/site-packages/sqlalchemy/orm/session.py", > > line 2363, in _flush > transaction.rollback(_capture_exception=True) > File > "/Users/hugo/Dropbox/lahey/api/.venv/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py", > > line 66, in __exit__ > compat.reraise(exc_type, exc_value, exc_tb) > File > "/Users/hugo/Dropbox/lahey/api/.venv/lib/python3.6/site-packages/sqlalchemy/util/compat.py", > > line 187, in reraise > raise value > File > "/Users/hugo/Dropbox/lahey/api/.venv/lib/python3.6/site-packages/sqlalchemy/orm/session.py", > > line 2327, in _flush > flush_context.execute() > File > "/Users/hugo/Dropbox/lahey/api/.venv/lib/python3.6/site-packages/sqlalchemy/orm/unitofwork.py", > > line 370, in execute > postsort_actions = self._generate_actions() > File > "/Users/hugo/Dropbox/lahey/api/.venv/lib/python3.6/site-packages/sqlalchemy/orm/unitofwork.py", > > line 329, in _generate_actions > if action.execute(self): > File > "/Users/hugo/Dropbox/lahey/api/.venv/lib/python3.6/site-packages/sqlalchemy/orm/unitofwork.py", > > line 454, in execute > self.dependency_processor.presort_deletes(uow, delete_states) > File > "/Users/hugo/Dropbox/lahey/api/.venv/lib/python3.6/site-packages/sqlalchemy/orm/dependency.py", > > line 419, in presort_deletes > self._passive_delete_flag) > File > "/Users/hugo/Dropbox/lahey/api/.venv/lib/python3.6/site-packages/sqlalchemy/orm/unitofwork.py", > > line 225, in get_attribute_history > attributes.LOAD_AGAINST_COMMITTED) > File > "/Users/hugo/Dropbox/lahey/api/.venv/lib/python3.6/site-packages/sqlalchemy/orm/attributes.py", > > line 928, in get_history > current = self.get(state, dict_, passive=passive) > File > "/Users/hugo/Dropbox/lahey/api/.venv/lib/python3.6/site-packages/sqlalchemy/orm/attributes.py", > > line 603, in get > value = self.callable_(state, passive) > File > "/Users/hugo/Dropbox/lahey/api/.venv/lib/python3.6/site-packages/sqlalchemy/orm/strategies.py", > > line 623, in _load_for_state > return self._emit_lazyload(session, state, ident_key, passive) > File "<string>", line 1, in <lambda> > File > "/Users/hugo/Dropbox/lahey/api/.venv/lib/python3.6/site-packages/sqlalchemy/orm/strategies.py", > > line 747, in _emit_lazyload > result = q(session).params(**params).all() > File > "/Users/hugo/Dropbox/lahey/api/.venv/lib/python3.6/site-packages/sqlalchemy/ext/baked.py", > > line 399, in all > return list(self) > File > "/Users/hugo/Dropbox/lahey/api/.venv/lib/python3.6/site-packages/sqlalchemy/ext/baked.py", > > line 296, in __iter__ > baked_context = bq._bake(self.session) > File > "/Users/hugo/Dropbox/lahey/api/.venv/lib/python3.6/site-packages/sqlalchemy/ext/baked.py", > > line 198, in _bake > query = self._as_query(session) > File > "/Users/hugo/Dropbox/lahey/api/.venv/lib/python3.6/site-packages/sqlalchemy/ext/baked.py", > > line 221, in _as_query > query = step(query) > File > "/Users/hugo/Dropbox/lahey/api/.venv/lib/python3.6/site-packages/sqlalchemy/orm/strategies.py", > > line 727, in <lambda> > strategy_options.Load.for_existing_path( > File > "/Users/hugo/Dropbox/lahey/api/.venv/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py", > > line 977, in __getattr__ > attr = getattr(self.module, key) > File > "/Users/hugo/Dropbox/lahey/api/.venv/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py", > > line 767, in __get__ > obj.__dict__[self.__name__] = result = self.fget(obj) > File > "/Users/hugo/Dropbox/lahey/api/.venv/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py", > > line 962, in module > % (self._il_path, self._il_addtl)) > ImportError: importlater.resolve_all() hasn't been called (this is > sqlalchemy.orm strategy_options) My model declaration for this object looks like this: import datetime from sqlalchemy_utils.types.password import PasswordType from sqlalchemy_utils import force_auto_coercion from app.extensions import db # Setup coercion of passwords force_auto_coercion() class User(db.Model): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(120), unique=True, nullable=False) password = db.Column(PasswordType(schemes=['pbkdf2_sha512']), nullable= False) name = db.Column(db.String(256)) created_at = db.Column(db.DateTime, default=datetime.datetime.now) updated_at = db.Column(db.DateTime, onupdate=datetime.datetime.now) I can delete objects of other models without trouble. I've tried to follow the code in the traceback, but can't really make sense of it. Could this have something to do with the PasswordType column from sqlalchemy_utils? Help is much appreciated! /Hugo -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
