Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is an InstrumentedList in Python?

During some set operations I encountered this error in Python:

TypeError: unhashable type: 'InstrumentedList'

What is an InstrumentedList in Python? I only found a few references related to SQLAlchemy. Is this a SQLAlchemy implementation of lists or something?

By the way, it happens while doing:

set(self.some_list)

where

print type(self.some_list) # <type 'list'>
like image 314
Aufwind Avatar asked Jul 11 '11 18:07

Aufwind


People also ask

What is ORM SQLAlchemy?

SQLAlchemy is a library that facilitates the communication between Python programs and databases. Most of the times, this library is used as an Object Relational Mapper (ORM) tool that translates Python classes to tables on relational databases and automatically converts function calls to SQL statements.

What is Backref in SQLAlchemy?

The sqlalchemy backref is one of the type keywords and it passed as the separate argument parameters which has to be used in the ORM mapping objects. It mainly includes the event listener on the configuration attributes with both directions of the user datas through explicitly handling the database relationships.


2 Answers

Yes, SQLAlchemy uses it to implement a list-like object which is aware of insertions and deletions of related objects to an object (via one-to-many and many-to-many relationships).

like image 69
Vinay Sajip Avatar answered Oct 16 '22 09:10

Vinay Sajip


Yes it's part of SQLAlchemy API. Here is the class reference:

http://docs.sqlalchemy.org/en/latest/orm/collections.html#sqlalchemy.orm.collections.InstrumentedList

like image 45
AJ. Avatar answered Oct 16 '22 10:10

AJ.