I have tens (potentially hundreds) of thousands of permanent objects that I want to generate in a multi-threaded way due to the necessary processing.
While the creation of objects occurs in separate streams (using Flask-SQLAlchemy extension flags with sessions with binding), the recording of generated objects in the database is called in 1 place after the generation is completed.
I believe that the problem is that the objects being created are part of several existing relationships, thereby causing the identification to be automatically added to the map, despite the fact that they are created in separate parallel threads without an explicit session in any of the threads.
I was hoping to keep the generated objects in a single list, and then write the entire list (using a single session object) to the database. This results in an error:
AssertionError: A conflicting state is already present in the identity map for key (<class 'app.ModelObject'>, (1L,))
Therefore, why I believe that the ID card is already full, because when I try to add and commit using a global session outside of the parallel code, an approval error will be raised.
The last detail is that any session object (in brackets or otherwise, since I donโt quite understand how automatic adding to an identification card works in case of multithreading), I canโt find a way / donโt know how to get a link to them so that even if I wanted to deal with a separate session for each process, I could.
Any advice is appreciated. The only reason I am not posting the code (for now) is that it is difficult to immediately draw a working example from my application. I will post if someone really needs to see this.
source share