3

Given the following sess query:

sess = DBSession()  
reg =  sess.query(Registration,Schedule).join(Schedule,Registration.classcode==Schedule.classcode).filter(Registration.registration_no==reg_id)

How the heck do I address the fields in the result 'reg'?

reg.timeofentry throws an error: TypeError: Can't convert 'int' object to str implicitly

I am rapidly learning to loath SQLAlchemy for all it's cryptic wrappers around perfectly simply SQL syntaxes.

1 Answer 1

6

oddly enough, the names within the named tuple row as returned from iterating the result reg in this case would be be Registration and Schedule:

for row in reg:
   print row.Registration, row.Schedule

I'm not able to reproduce your specific error message "can't convert 'int' object to str implicitly". If I attempt to access a name on the KeyedTuple that doesn't exist, there's a clear message:

AttributeError: 'KeyedTuple' object has no attribute 'imfake'

The behavior of the return value of query should be less cryptic after reading the intro to Querying in the ORM tutorial.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.