Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Federico Caselli
    @CaselIT
    what do you mean? sqlalchemy by its own does not have any process
    Alex Grönholm
    @agronholm
    perhaps that is a reference to PostgreSQL where client connections are shown as "processes" connecting to the server
    GauravPandey-NECI
    @Gauravp-NEC
    Hi, How we can check the "os.fork" have implemented in SQLalchemy source code?
    How we can check the "os.fork" functionality is used in SQLalchemy??
    Alex Grönholm
    @agronholm
    @Gauravp-NEC are you trying to ask if os.fork() is used in sqlalchemy, or what
    4 replies
    Varsha Ramesh
    @varsharmsh

    Hi,
    We are trying to use SQLAlchemy compile to generate queries in different dialects. It is somehow not working for complex queries.
    QUERY
    SELECT partsupp.ps_supplycost, region.r_regionkey FROM region JOIN partsupp ON
    (partsupp.ps_partkey 698) < region.r_regionkey

    SELECT OBJECT

    <class 'sqlalchemy.sql.selectable.Select'>
    SELECT partsupp.ps_supplycost, region.r_regionkey
    FROM region JOIN partsupp ON
    (partsupp.ps_partkey + %(ps_partkey_1)s) < region.r_regionkey

    USAGE

    Federico Caselli
    @CaselIT
    I'm not sure what is the issue @varsharmsh
    2 replies
    Cyril Margorin
    @comargo
    Hello there.
    I've got a noob question.
    https://gist.github.com/comargo/0ca997e45ce2d59ca456f556c6d5a07d
    How can I make relationship(..., backref="...") populate parent class before using it?
    but you should probably use back_populates
    Cyril Margorin
    @comargo
    @CaselIT Thanks!!! the configure_mappers() was exactly what I looked for, but why back_populates is better then backref? It requires me to write the same thing twice....
    Federico Caselli
    @CaselIT
    you write the other side of the relationshinp
    in the 99% or the cases it's better since it's explicit and it better to reason about once you have to re-read old code and you don't remember who defined that backref
    Cyril Margorin
    @comargo
    Well... ok, probably you right. Thank you for you help!
    Luis Roel
    @luisroel91
    Hello all! Anyone have any examples on how to use Automap with asyncpg? Even when running Base.prepare in run_sync call, still get (NoInspectionAvailable) exception
    Hunter Kiely
    @hkiely
    Has anything replaced SQLAlchemy-ImageAttach for SQLAlchemy 1.4?
    Hunter Kiely
    @hkiely
    If sqlalchemy.ext.declarative is built in version 1.4, can anyone link to a tutorial?
    Alex Grönholm
    @agronholm
    @hkiely it's no longer an extension; can you really not find the tutorial in the documentation?
    Nicolai Mogensen
    @NicolaiMogensen
    Can anyone explain why a call to __table__.columns on the base class of a model, also gives me all the columns of all classes that inherit the baseclass? How do i figure out what columns a specific class has, base or not
    Alex Grönholm
    @agronholm
    can you not determine that from the column objects themselves?
    Nicolai Mogensen
    @NicolaiMogensen
    Do they have a property that tells you what type of model they belong to?
    Alex Grönholm
    @agronholm
    I can't remember off hand, but dir(column) should give you a list a properties to check out
    Nicolai Mogensen
    @NicolaiMogensen
    I'll try it out, thanks for the pointer. But is the idea of having different table models, based on what the database might have implemented wrong? I see that i can't point them to the same table and schema. I might need to do something different. My idea was to have different classes based on what the client expects, but maybe i'm better off creating views in the actual database?
    Nicolai Mogensen
    @NicolaiMogensen
    Guess i'm trying to achieve https://docs.sqlalchemy.org/en/14/orm/inheritance.html#single-table-inheritance single table inheritance, i will dig around
    Hunter Kiely
    @hkiely
    @agronholm this is what I hav found dahlia/sqlalchemy-imageattach#47 .
    Alex Grönholm
    @agronholm
    yes, declarative now lives in a different module as the linked documentation points out
    Hunter Kiely
    @hkiely
    @agronholm Is ImageAttach unmaintained with 1.4?
    Alex Grönholm
    @agronholm
    I have never heard of this imageattach thing
    Jonathan Vanasco
    @jvanasco
    That's a third party library that hasn't been updated in over 4 years
    Tomas Wilhelmsson
    @tomaswilhelmsson
    hey! Im trying to build a table with some properties from two tables, ive got this now and it does just what i want .. only problem is that its dog slow ... any better way to do the same thing ? https://paste.ofcode.org/VVtKByEvTkuBHwGDXY9757
    Federico Caselli
    @CaselIT
    you may create a select and map that to __table__
    alovicious72
    @alovicious72

    I've been a relatively casual user of SQLALchemy until now, but I'm trying to really get a grip on Session behavior. I'm having trouble understanding a description of Session identity map behavior in the "Querying (1.x Style)" section of the documentation here: https://docs.sqlalchemy.org/en/14/orm/session_basics.html

    The description I'm struggling with is this:

    When ORM objects are returned in results, they are also stored in the identity map. When an incoming database row has a primary key that matches an object which is already present, the same object is returned, and those attributes of the object which already have a value are not re-populated.

    I understand that first sentence - but I am struggling with the second one. It seems like its describing the behavior when a returned row has a database identity that matches an object that is already in the identity map...and maybe how it resolves conflicts if their attributes do not have matching values - but I can't quite understand it.

    Can somebody reword that - or even better - suggest a code snippet that I can run to better understand what is going on? Thanks

    Gord Thompson
    @gordthompson
    @alovicious72 - Does this help?
    engine1 = sa.create_engine(connection_uri)
    engine2 = sa.create_engine(connection_uri)
    
    
    class Thing(Base):
        __tablename__ = "thing"
        id = Column(Integer, primary_key=True, autoincrement=False)
        txt = Column(String(50))
    
    
    Base.metadata.drop_all(engine1)
    Base.metadata.create_all(engine1)
    
    with Session(engine1) as session1:
        session1.add(Thing(id=1, txt="from session1"))
        session1.commit()
        thing1 = session1.get(Thing, 1)  # re-retrieve object into identity map
        with engine2.begin() as conn2:
            # simulate update from external process
            conn2.exec_driver_sql("UPDATE thing SET txt = '***updated***' WHERE id = 1")
        x = session1.execute(select(Thing).where(Thing.id == 1)).scalar()
        print(f"x and thing1 {'ARE' if x == thing1 else 'are NOT'} the same object")
        # x and thing1 ARE the same object
        print(f"thing1.txt is '{thing1.txt}'")
        # thing1.txt is 'from session1'
        session1.expire(thing1)  # force reload on subsequent access
        print(f"thing1.txt is '{thing1.txt}'")
        # thing1.txt is '***updated***'
    alovicious72
    @alovicious72
    Hi @gordthompson Thanks for posting this! So - would "thing1.txt == x.txt" evaluate to "True" just before the "session1.expire(thing1)" executes? I expect so (given that "x" and "thing1" are the same object)...but I am going to fire up my IDE and run this to find out. I think I understand what is happening here, but what to run that particular test to be sure.
    alovicious72
    @alovicious72

    @gordthompson Yes, thankfully (though not unexpectedly...as "thing1" and "x" are the same object) - their "txt" attributes have the same value. OK, so I think I understand what's going on here...and here is how I know have rewritten that 2nd sentence in my own mind:

    When an incoming database row has a primary key that matches an object which is already present, the same object is returned, and those attributes of the object which already have a value will continue to return that value - even if the value returned by the row is different.

    (In effect, the returned row does not overwrite the existing attribute value - should one already be set - on the object.

    Have I got it right?

    Gord Thompson
    @gordthompson
    @alovicious72 - Sounds right to me.
    alovicious72
    @alovicious72
    Great. Thank you, @gordthompson
    PalmaAnderson
    @PalmaAnderson
    Hello everyone
    i'm new here, first time creating a REST API
    and it seens to be working fine when I use postman(GET/POST/DELETE), but i get into CORS problem when my website (another python flask bootstrap) tries to run it
    William Edwards
    @NominaSumpta_twitter
    Hi. I have a model (inherited from declarative_base), and I'd like to check if I'm working with the model I expect. I currently have 'if str(model) == "app.models.Cluster":' where model is a model derived from declarative_base - is there a more elegant way to check equality?
    Federico Caselli
    @CaselIT
    are you looking for isinstance?
    William Edwards
    @NominaSumpta_twitter
    Probably; but it doesn't work for me. print(model,Cluster,type(model),type(Cluster),isinstance(model, Cluster),str(model)) yields <class 'app.models.Cluster'> <class 'app.models.Cluster'> <class 'sqlalchemy.ext.declarative.api.DeclarativeMeta'> <class 'sqlalchemy.ext.declarative.api.DeclarativeMeta'> False <class 'app.models.Cluster'> - not sure why isinstance evaluates to False as the type and string representation are the same
    1 reply
    Federico Caselli
    @CaselIT
    well model there is a class, just an alias of Cluster, not an instance of it. you can just use ==. model == Cluster. you should probably not call it model, maybe something like modelCls or something
    2 replies
    felixfarquharson
    @felixfarquharson
    Hello, does anyone know how to set the cache to 1 second on tornado_sqlalchemy?
    Jonathan Vanasco
    @jvanasco
    That sounds like a question for the tornado-sqlalchemy or tornado developers. sqlalchemy doesn't have a timed cache.
    felixfarquharson
    @felixfarquharson
    thanks anyway :\
    dzpt
    @dzpt
    Hi all, i use sqlacodegen to gen oracle tables
    but it generates Table() instead of class
    even after using sqlacodegen --generator dataclasses