Does anyone know how to handle "NoSuchColumnError"

223 views
Skip to first unread message

Ofir Herzas

unread,
Apr 30, 2015, 11:00:46 AM4/30/15
to sqlal...@googlegroups.com
Hi,
I'm using sqlalchemy 0.9.7 and cx_oracle 5.1.3 and every once in a while (inconsistent), I get the following error:

Traceback (most recent call last):
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 1919, in flush
    self._flush(objects)
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 2037, in _flush
    transaction.rollback(_capture_exception=True)
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py", line 60, in __exit__
    compat.reraise(exc_type, exc_value, exc_tb)
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 2001, in _flush
    flush_context.execute()
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py", line 372, in execute
    rec.execute(self)
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py", line 526, in execute
    uow
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py", line 65, in save_obj
    mapper, table, insert)
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py", line 602, in _emit_insert_statements
    execute(statement, params)
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 729, in execute
    return meth(self, multiparams, params)
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/sql/elements.py", line 321, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 826, in _execute_clauseelement
    compiled_sql, distilled_params
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 978, in _execute_context
    context._fetch_implicit_returning(result)
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 815, in _fetch_implicit_returning
    ipk.append(row[c])
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/result.py", line 331, in _key_fallback
    expression._string_or_unprintable(key))
NoSuchColumnError: "Could not locate column in row for column 't_shift_employee_change.id'"
[30/Apr/2015:15:55:17] EXCEPTION
# ---- EXCEPTION DESCRIPTION BEGIN ---- #
# ---- Type ---- #
NoSuchColumnError
# ---- Detail ---- #
"Could not locate column in row for column 't_shift_employee_change.id'"
# ---- Traceback ---- #
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 1919, in flush
    self._flush(objects)
-
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 2037, in _flush
    transaction.rollback(_capture_exception=True)
-
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py", line 60, in __exit__
    compat.reraise(exc_type, exc_value, exc_tb)
-
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 2001, in _flush
    flush_context.execute()
-
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py", line 372, in execute
    rec.execute(self)
-
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py", line 526, in execute
    uow
-
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py", line 65, in save_obj
    mapper, table, insert)
-
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py", line 602, in _emit_insert_statements
    execute(statement, params)
-
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 729, in execute
    return meth(self, multiparams, params)
-
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/sql/elements.py", line 321, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
-
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 826, in _execute_clauseelement
    compiled_sql, distilled_params
-
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 978, in _execute_context
    context._fetch_implicit_returning(result)
-
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 815, in _fetch_implicit_returning
    ipk.append(row[c])
-
  File "/opt/enigmai/ve/python-2.7.6/lib/python2.7/site-packages/sqlalchemy/engine/result.py", line 331, in _key_fallback
    expression._string_or_unprintable(key))

# ---- EXCEPTION DESCRIPTION END ---- #

I saw several posts about this issue but I didn't find a solution.
Restarting my service seems to fix the issue for a while.

BTW: This error is linked to a mixin class I've created for track-changes based on the version mixin from

http://docs.sqlalchemy.org/en/latest/_modules/examples/versioned_history/history_meta.html


Mike Bayer

unread,
Apr 30, 2015, 12:03:10 PM4/30/15
to sqlal...@googlegroups.com
this error refers to a wide variety of situations where the ORM is running a query that is failing to compose correctly.  It's a bug in SQLAlchemy.  That you are getting this within an INSERT statement from the RETURNING clause in oracle strongly suggests this is a bug in the Oracle dialect.   If you can post minimal mappings and the stack trace here as a bug report that would be very helpful.

Note also that the Oracle dialect doesn't do very well with composite primary keys in conjunction with RETURNING.    There may have been some limitations I came across in my testing here, so there is a note at http://docs.sqlalchemy.org/en/rel_1_0/dialects/oracle.html#returning-support regarding this.     While I still want to know how you're getting exactly this kind of error since it would be nice to anticipate it better, the section here illustrates the implicit_returnining=False flag that would resolve these errors you're getting.



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

Ofir Herzas

unread,
May 3, 2015, 2:01:43 AM5/3/15
to sqlal...@googlegroups.com
Hi Michael,
Thank you very much for your fast response. I will give it a try.

I tried to remove unneeded stuff but I think that the problem is in the track_changes mixin as I never got this error before using it.
If you need more stuff or do find something, I'd be happy to know.

BTW: for initialization, I use:

DB_URL="oracle://user:pass@url/db"
engine = create_engine(DB_URL, echo=False, pool_recycle=3600)
Session = scoped_session(sessionmaker(bind=engine, expire_on_commit=False))
session = tracked_session(Session())
Base = declarative_base()

Cheers,
Ofir
ShiftEmployee.py
track_changes.py

Mike Bayer

unread,
May 3, 2015, 11:06:52 AM5/3/15
to sqlal...@googlegroups.com

On 5/3/15 2:01 AM, Ofir Herzas wrote:
Hi Michael,
Thank you very much for your fast response. I will give it a try.

I tried to remove unneeded stuff but I think that the problem is in the track_changes mixin as I never got this error before using it.
If you need more stuff or do find something, I'd be happy to know.

OK, passing "implicit_returning=False" to the Table objects created by the history mixin should fix it on your end.   I'll try to find some time to experiment with it.

Ofir Herzas

unread,
May 3, 2015, 12:00:59 PM5/3/15
to sqlal...@googlegroups.com

Is there any danger using the implicit_returning=False on the engine? Or is it the same?

--
You received this message because you are subscribed to a topic in the Google Groups "sqlalchemy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy/TpJ86vA64DM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlalchemy+...@googlegroups.com.

Mike Bayer

unread,
May 3, 2015, 6:47:12 PM5/3/15
to sqlal...@googlegroups.com


On 5/3/15 12:00 PM, Ofir Herzas wrote:

Is there any danger using the implicit_returning=False on the engine? Or is it the same?


not "dangerous" but the implicit returning feature is very nice for INSERT statements done by the ORM, assuming you are using sequences to generate primary key values; it saves a round trip of executing the sequence ahead of time.

Ofir Herzas

unread,
May 4, 2015, 3:23:23 AM5/4/15
to sqlal...@googlegroups.com

For some reason, I get the following error while using this attribute on the table:

python-2.7.6/lib/python2.7/site-packages/sqlalchemy/sql/schema.py:500: SAWarning: Can't validate argument 'implicit_returning'; can't locate any SQLAlchemy dialect named 'implicit'

  self._validate_dialect_kwargs(kwargs)

 

I should note that the application I'm developing uses other DB's also (e.g mysql) nd that I got this error while checking the application on mysql.

Mike Bayer

unread,
May 4, 2015, 11:16:12 AM5/4/15
to sqlal...@googlegroups.com


On 5/4/15 3:23 AM, Ofir Herzas wrote:

For some reason, I get the following error while using this attribute on the table:

python-2.7.6/lib/python2.7/site-packages/sqlalchemy/sql/schema.py:500: SAWarning: Can't validate argument 'implicit_returning'; can't locate any SQLAlchemy dialect named 'implicit'

  self._validate_dialect_kwargs(kwargs)

 

I should note that the application I'm developing uses other DB's also (e.g mysql) nd that I got this error while checking the application on mysql.


implicit_returning is one of the core arguments of Table.   That error message would happen if you were to send implicit_returning to some other kind of object, like an Index.

Here is a diff against history_meta showing where the argument would go:

diff --git a/examples/versioned_history/history_meta.py b/examples/versioned_history/history_meta.py
index 6d7b137..b5eadcb 100644
--- a/examples/versioned_history/history_meta.py
+++ b/examples/versioned_history/history_meta.py
@@ -106,7 +106,8 @@ def _history_mapper(local_mapper):
             local_mapper.local_table.name + '_history',
             local_mapper.local_table.metadata,
             *cols,
-            schema=local_mapper.local_table.schema
+            schema=local_mapper.local_table.schema,
+            implicit_returning=False
         )
     else:
         # single table inheritance.  take any additional columns that may have

Ofir Herzas

unread,
May 4, 2015, 2:44:34 PM5/4/15
to sqlal...@googlegroups.com

That part did work, but I keep a table class also (just so the table will be created if it doesn't exist), but adding the argument to the table args generates the error:

 

class ShiftEmployeeChange(Base):

    __tablename__ = "t_shift_employee_change"

    __table_args__ = {'extend_existing': True, 'implicit_returning':False}

   

    id = sa.Column(Identifier, sa.Sequence('%s_id_seq' % __tablename__), nullable=False, primary_key=True)

    field1 = sa.Column(sa.BigInteger, nullable=False)

    field2 = sa.Column(sa.BigInteger)

    field3 = sa.Column(sa.Date, nullable=False)

    field4 = sa.Column(sa.Boolean, default=False)

    changed_at = sa.Column(sa.DateTime, nullable=False, default=datetime.datetime.now)

    changed_by = sa.Column(sa.BigInteger)

 

Do I need the argument there also?

Mike Bayer

unread,
May 4, 2015, 2:51:32 PM5/4/15
to sqlal...@googlegroups.com


On 5/4/15 2:44 PM, Ofir Herzas wrote:

That part did work, but I keep a table class also (just so the table will be created if it doesn't exist), but adding the argument to the table args generates the error:

 

class ShiftEmployeeChange(Base):

    __tablename__ = "t_shift_employee_change"

    __table_args__ = {'extend_existing': True, 'implicit_returning':False}

   

    id = sa.Column(Identifier, sa.Sequence('%s_id_seq' % __tablename__), nullable=False, primary_key=True)

    field1 = sa.Column(sa.BigInteger, nullable=False)

    field2 = sa.Column(sa.BigInteger)

    field3 = sa.Column(sa.Date, nullable=False)

    field4 = sa.Column(sa.Boolean, default=False)

    changed_at = sa.Column(sa.DateTime, nullable=False, default=datetime.datetime.now)

    changed_by = sa.Column(sa.BigInteger)

 

Do I need the argument there also?


I'm making the guess that this error is happening in those cases where a table has a composite primary key, which is what the versioning recipe generates.  But this table doesn't have that, so you shouldn't need it there.   But the implicit_returning directive shouldn't cause any errors or warnings either.  I don't get the same warning on my end.
Reply all
Reply to author
Forward
0 new messages