Re: [sqlalchemy] session.add() neglecting some of my objects to be added

2017-07-13 Thread David Laredo Razo
i did as you instructed me but the error persists. This is the example code im talking about Session = sessionmaker() session = Session() mapper = inspect(ThermafuserReading) readings = list() header = ["hex(id(object))", "is transient", "is pending", "is persistent", "is detached", "is

[sqlalchemy] Re: What is a best practice model for cache instances using their detached state?

2017-07-13 Thread Jinghui Niu
I just tried a revised version of the cache consumer method as follows: def Record_entries_count(self): # import pdb; pdb.set_trace() db = cherrypy.request.db_session query_subset = db.query(MyClass).merge_result(self. search_result_cache) result =

Re: [sqlalchemy] What is a best practice model for cache instances using their detached state?

2017-07-13 Thread Jinghui Niu
Hi Mike, I've read the example of dogpile caching. For my case dogpile.cache seems to be a overkill, could you please provide a thinner example of using Query.merge_result without involving another library? Thanks. On Thu, Jul 13, 2017 at 8:07 PM, Jinghui Niu wrote: >

Re: [sqlalchemy] What is a best practice model for cache instances using their detached state?

2017-07-13 Thread Jinghui Niu
Thanks Mike. Just to clarify, so instead of caching a Query object, I should cache all those queried instance in my `self.search_result_cache`, is this the idea? Is there a way to just relay Query object from one method to another? Which seems a little simpler to me. On Thu, Jul 13, 2017 at 7:20

Re: [sqlalchemy] What is a best practice model for cache instances using their detached state?

2017-07-13 Thread Mike Bayer
you need to use Session.merge and/or Query.merge_result so that a *copy* of the detached object is placed into the Session.In particular, Query.merge_result was created for the use case of caching result sets.

Re: [sqlalchemy] inline polymorphic_load for single table inheritance

2017-07-13 Thread Mike Bayer
On Thu, Jul 13, 2017 at 4:37 PM, Shane Carey wrote: > When I have single table inheritance, how can I use the new 'inline' > polymorphic_load feature to only query a subset of child classes? 'inline' polymorphic load is only about using fewer SQL queries to load

[sqlalchemy] What is a best practice model for cache instances using their detached state?

2017-07-13 Thread Jinghui Niu
I have a web application served by cherrypy (, which is multi-threaded. ) I'm trying to cache a set of rows queried from database using `self.search_result_cache` variable on the GUI_Server object. On my front-end, the web first request `list_entries` to prepare the rows and stores them on

[sqlalchemy] Re: inline polymorphic_load for single table inheritance

2017-07-13 Thread Shane Carey
After reading the documentation more thoroughly, I realized that with_polymorphic does not filter the result set by subclasses included, it only eagerly loads the attributes of those subclasses. In order to filter on certain subclasses, am I forced to user Query.filter() for that purpose? --

[sqlalchemy] inline polymorphic_load for single table inheritance

2017-07-13 Thread Shane Carey
When I have single table inheritance, how can I use the new 'inline' polymorphic_load feature to only query a subset of child classes? from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class Parent(Base):

Re: [sqlalchemy] session.add() neglecting some of my objects to be added

2017-07-13 Thread Mike Bayer
On Thu, Jul 13, 2017 at 12:31 AM, David Laredo Razo wrote: > Hello, I am using SQLAlchemy version 1.2.0b1 > > > > So far so go, the problem arises when I add readings to the session via > session.add_all(readings). I only get the last element in my list added, > e.g.

Re: [sqlalchemy] Re: SQLAlchemy 1.2.0b1 released

2017-07-13 Thread yoch . melka
OK, thank a lot ! Le jeudi 13 juillet 2017 06:01:45 UTC+3, Mike Bayer a écrit : > > this is how that would have to be mapped, hypothetically: > > class EngineerBase(Person): > __tablename__ = 'engineer' > > id = Column(ForeignKey('person.id'), primary_key=True) > engineer_name =