Hi,

SQLalchemy rollbacks an insert command with out the reason for  failure. 
I am using Mysql

2017-10-06 15:23:22,170 INFO 
 [sqlalchemy.engine.base.Engine:1140][b'uWSGIWorker2Core0'] INSERT INTO 
group_message_22f9b36c (group_id, group_topic_id, score, user_id, uname, 
msg, created_at, updated_at) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)
2017-10-06 15:23:22,171 INFO 
 [sqlalchemy.engine.base.Engine:1143][b'uWSGIWorker2Core0'] (11, 1, 0, 6, 
'sammy', 'dsfdsf', datetime.datetime(2017, 10, 6, 20, 23, 22, 169932), 
datetime.datetime(2017, 10, 6, 20, 23, 22, 169932))
2017-10-06 15:23:22,182 INFO 
 [sqlalchemy.engine.base.Engine:699][b'uWSGIWorker2Core0'] ROLLBACK


when I run the same command on Mysql workbench, it goes through fine.

*How do I know the reason for failure. It just prints ROLLBACK ?*

I am using pyramid_tm + zope_sqlalchemy


@contextmanager
def session_shardid(session, shardid):
    """Apply the "shard" id to all SQL emitted by the given Session.
    """
    session.info["shard"] = shardid
    yield
    del session.info["shard"]


@listens_for(Engine, "before_cursor_execute", retval=True)
def _apply_shard_id(connection, cursor, statement, parameters,
                    context, executemany):
    """Apply a "shard id" to statements.

    Similar to the comment listener, we alter the statement on the
    fly replacing occurrences of "_shard_" with the current "shard id".

    """
    session_info = connection.info.get('session_info', {})
    if "shard" in session_info:
        statement = statement.replace("_shardid_", session_info["shard"])
      

    return statement, parameters
gmsg = Group()

... fill all the values
with session_shardid(DBSession(), self.group.grp_hash):
            DBSession.add(gmsg)
            DBSession.flush()

I know I am doing something wrong in my declaration, but how do I know 
reason for failure from SQLAlchemy

Srikanth B

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to