AttributeError: 'NoneType' object has no attribute 'accepts_scalar_loader'

1,078 views
Skip to first unread message

dewey

unread,
Sep 15, 2015, 1:03:00 PM9/15/15
to sqlalchemy
I've got a SA session, and i'm running the following:

cot = sess.query(MyTable).get( int(someIntAsString) )

I'm seeing the error:

AttributeError: 'NoneType' object has no attribute 'accepts_scalar_loader'

I'm guessing that means the record was not found......any suggestions what else I should look for??

Thanks,
Dewey

Mike Bayer

unread,
Sep 15, 2015, 1:45:58 PM9/15/15
to sqlal...@googlegroups.com
full stack trace might shed some light on what's being misinterpreted




Thanks,
Dewey
--
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.

dewey

unread,
Sep 15, 2015, 2:05:35 PM9/15/15
to sqlalchemy

The contents of the full traceback was:


Traceback (most recent call last):

 File "/opt/paysys/python/lib/python2.7/site-packages/celery/app/trace.py", line 240, in trace_task

   R = retval = fun(*args, **kwargs)

 File "/opt/paysys/python/lib/python2.7/site-packages/celery/app/trace.py", line 438, in __protected_call__

   return self.run(*args, **kwargs)

 File "/opt/paysys/builds/20150907103013/source/jobs/spawn.py", line 238, in loaderDaily

   startLoaderViaQueue(jobParams)

 File "/opt/paysys/builds/20150907103013/source/jobs/datain/loader.py", line 459, in startViaQueue

   start(**job_params)

 File "/opt/paysys/builds/20150907103013/source/jobs/datain/loader.py", line 443, in start

   startLoader(sess, jobArgs)  # , useFileNameForProcessDay=True

 File "/opt/paysys/builds/20150907103013/source/jobs/datain/loader.py", line 404, in startLoader

   result = endFileProcessingFunc(sess, jobArgs, log, None)   # do any final work on the DB

 File "/opt/paysys/builds/20150907103013/source/jobs/datain/storage/fixed.py", line 327, in examinerStoreCtrAtts

   cot = sess.query(ContribTitle).get(int(cot_gem_id))

 File "/opt/paysys/python/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 840, in get

   return loading.load_on_ident(self, key)

 File "/opt/paysys/python/lib/python2.7/site-packages/sqlalchemy/orm/loading.py", line 231, in load_on_ident

   return q.one()

 File "/opt/paysys/python/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2395, in one

   ret = list(self)

 File "/opt/paysys/python/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2437, in __iter__

   self.session._autoflush()

 File "/opt/paysys/python/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 1198, in _autoflush

   self.flush()

 File "/opt/paysys/python/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 1919, in flush

   self._flush(objects)

 File "/opt/paysys/python/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 2037, in _flush

   transaction.rollback(_capture_exception=True)

 File "/opt/paysys/python/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py", line 63, in __exit__

   compat.reraise(type_, value, traceback)

 File "/opt/paysys/python/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 2037, in _flush

   transaction.rollback(_capture_exception=True)

 File "/opt/paysys/python/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 403, in rollback

   transaction._rollback_impl()

 File "/opt/paysys/python/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 434, in _rollback_impl

   self._restore_snapshot(dirty_only=self.nested)

 File "/opt/paysys/python/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 288, in _restore_snapshot

   s._expire(s.dict, self.session.identity_map._modified)

 File "/opt/paysys/python/lib/python2.7/site-packages/sqlalchemy/orm/state.py", line 385, in _expire

   if impl.accepts_scalar_loader and \

Mike Bayer

unread,
Sep 15, 2015, 2:22:56 PM9/15/15
to sqlal...@googlegroups.com
that element cannot be None, unless something is very broken with the mappings and/or the way the program is being run (e.g. weird things with threads perhaps).  Would need to see a reproducing test case (See http://stackoverflow.com/help/mcve).

dewey

unread,
Sep 15, 2015, 3:56:58 PM9/15/15
to sqlalchemy
I'll see if I can reproduce this in a simple example.....it's currently in a job being run every night from a Celery-Beat scheduler......

Interestingly, just changing the data in the DB made this problem go away temporarily.......we were seeing this error thrown every night on staging for 5 days straight,
But after we copied the Prod data into staging, it went away for about a week.....

This morning, it threw on both staging and prod......first time we've seen it in Prod....

Thanks for your thoughts...
Dewey

Mike Bayer

unread,
Sep 16, 2015, 7:24:47 PM9/16/15
to sqlal...@googlegroups.com

dewey

unread,
Sep 16, 2015, 8:05:28 PM9/16/15
to sqlalchemy
Hey Mike,
I've found and fixed (with help) my problem, but I thought I'd describe it here to support anyone else who hits this...
Was not a threading issue......it was a combination of:
  • data-edge case
  • bug in our code
  • bug in how SA was reporting a failure...
I was adding a model object to the session as follows:
rec = get_or_create(sess, CtrAtt, ctrAttSearchVals, ctrAttNewVals ) 
sess.add(rec)

next I was looking up a record that was needed as an FKEY to the CtrAtt record I just put in the session  (oops.....our bug)

cot = sess.query(ContribTitle).get(int(cot_gem_id))

That query was of course flushing the session...but the record sought via "ContribTitle" was not found  (the data-edge case)

When SA saw the FKEY integrity error, it was attempting to roll-back the transaction.....and it was not showing the DB Integrity error....

Somewhere in that process, SA attempted to access a null "impl" object and confusingly throwing the:

'NoneType' object has no attribute 'accepts_scalar_loader'

Regards,
Dewey

Mike Bayer

unread,
Sep 17, 2015, 10:45:16 AM9/17/15
to sqlal...@googlegroups.com


On 9/16/15 8:05 PM, dewey wrote:
Hey Mike,
I've found and fixed (with help) my problem, but I thought I'd describe it here to support anyone else who hits this...
Was not a threading issue......it was a combination of:
  • data-edge case
  • bug in our code
  • bug in how SA was reporting a failure...
I was adding a model object to the session as follows:
rec = get_or_create(sess, CtrAtt, ctrAttSearchVals, ctrAttNewVals ) 
sess.add(rec)


Reply all
Reply to author
Forward
0 new messages