not as much set-ordering as gc, most likely. add populate_existing to the query, that also should force the lazy loader to take effect
On Thu, Jan 5, 2023, at 9:00 AM, Mike Bayer wrote: > the "b" object in question is not really "lazy loaded" in the usual sense > here because it's already present in the session, that looks like an unexpire > query. the delete() might be just changing something where the issue comes > down to a set-ordering issue, perhaps. try adding session.expunge_all() > before the query and see if that makes things look more expected. > > On Thu, Jan 5, 2023, at 1:27 AM, 'Tony Cosentini' via sqlalchemy wrote: >> Ok, I was able to at least create a script that easily reproduces what I'm >> seeing - >> https://gist.github.com/tonycosentini/22f42455c5068898efa473760e4f65ed >> >> We have some code that runs before our tests to ensure all the tables are >> empty. When that runs, load_only doesn't seem to work. It sounds bizarre, >> but that gist link contains a really short sample that reproduces the same >> behavior. I'm running 1.4.44. >> >> Tony >> >> On Thursday, January 5, 2023 at 11:09:40 AM UTC+8 Tony Cosentini wrote: >>> Funny enough, this is what I tried. I just wrote up a small sample script >>> using defaultload + load_only and sure enough it works. There must be >>> something in the code base I'm working with that prevents the load_only bit >>> from being applied. I'm pretty sure defaultload is woroking fine. I'll >>> report back if I find it. >>> >>> Thanks for clarifying! >>> >>> On Thursday, January 5, 2023 at 8:14:21 AM UTC+8 Michael Bayer wrote: >>>> yeah you can use defaultload.load_only >>>> >>>> >>>> defaultload(ModelA.model_b).load_only(ModelB.only_field) >>>> >>>> >>>> >>>> On Wednesday, January 4, 2023 at 3:15:02 AM UTC-5 [email protected] >>>> wrote: >>>>> Hi, >>>>> >>>>> This might be a strange question, but I tried to find this in the >>>>> documentation to no avail. >>>>> >>>>> Is it possible to use something like load_only to override which columns >>>>> are loaded in when loading a relationship (as in, a relationship that is >>>>> not loaded at first with the original query)? >>>>> >>>>> Something like: >>>>> class ModelB: >>>>> ... >>>>> >>>>> class ModelA: >>>>> model_b = relationship("ModelB") >>>>> >>>>> model_a = >>>>> session.query(ModelA).options(load_only(Model_b.only_field_i_want_in_the_future)).filter(ModelA.id==1).first() >>>>> >>>>> It's a bit strange, but I want to ensure if someone loads the model_b >>>>> property in the future, only specific columns are loaded in at first. >>>>> >>>>> I can do this if I just query for model_b via the foreign key instead of >>>>> using the relationship property, but I'd like to avoid that if possible. >>>>> >>>>> Sorry if this question is a bit weird/confusing, it's kind of a strange >>>>> use case. >>>>> >>>>> Thanks, >>>>> Tony >> >> >> -- >> SQLAlchemy - >> The Python SQL Toolkit and Object Relational Mapper >> >> http://www.sqlalchemy.org/ >> >> To post example code, please provide an MCVE: Minimal, Complete, and >> Verifiable Example. See http://stackoverflow.com/help/mcve for a full >> description. >> --- >> 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 [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/sqlalchemy/e2dc23f8-97cf-494e-8661-bc0267fdf075n%40googlegroups.com >> >> <https://groups.google.com/d/msgid/sqlalchemy/e2dc23f8-97cf-494e-8661-bc0267fdf075n%40googlegroups.com?utm_medium=email&utm_source=footer>. > > > > -- > SQLAlchemy - > The Python SQL Toolkit and Object Relational Mapper > > http://www.sqlalchemy.org/ > > To post example code, please provide an MCVE: Minimal, Complete, and > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > description. > --- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sqlalchemy/2c67aa85-06c9-4f64-bca9-fb2f0f91da7a%40app.fastmail.com > > <https://groups.google.com/d/msgid/sqlalchemy/2c67aa85-06c9-4f64-bca9-fb2f0f91da7a%40app.fastmail.com?utm_medium=email&utm_source=footer>. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/a46f6a33-51f4-4c50-bbd7-e4de035a448c%40app.fastmail.com.
