Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    morenonatural
    @morenonatural:envs.net
    [m]
    this is code that was working before converting everything to async calls
    Alex Grönholm
    @agronholm
    are you sure that register_composites() isn't psycopg2 specific?
    morenonatural
    @morenonatural:envs.net
    [m]
    it's from sqlalchemy_utils module ... it calls psycopg2 stuff underneath
    Alex Grönholm
    @agronholm
    that doesn't work if your driver is asyncpg and not psycopg2
    morenonatural
    @morenonatural:envs.net
    [m]
    I'm using postgresql+asyncpg + create_async_engine() and propagated that ... am I missing something?
    (mypy pointed the incompatibilities and I started by correcting that, this is like the first run for this code)
    Alex Grönholm
    @agronholm
    as I said, register_composites() seems specific to psycopg2 so it won't work if you use another driver
    morenonatural
    @morenonatural:envs.net
    [m]
    will look for psycopg2 code in my repo. thx for the pointers
    Alex Grönholm
    @agronholm
    is register_composites() your code?
    1 reply
    or why are you looking for psycopg2 code in your repo?
    1 reply
    morenonatural
    @morenonatural:envs.net
    [m]
    (about 10 people working in this repo... I'm asking around for any info as nobody covers the whole code)
    morenonatural
    @morenonatural:envs.net
    [m]

    oh, to anyone interested in sqlalchemy_utils.register_composites() + async

    kvesteri/sqlalchemy-utils#611

    Alex Bender
    @alex-bender
    Hello, is it possible to add some option during Sequence creation so upon deletion 'drop sequence CASCADE' would be issued instead of 'drop sequence' in ddl.compile. dialect is psql.
    I'm getting error cannot drop sequence sequence_ticket_number because other objects depend on it
    Alex Grönholm
    @agronholm
    I don't think so
    Alex Bender
    @alex-bender
    is there a way to set this cascade behaviour if Sequence is being used outside of relation?
    ticket_number = db.Column( db.Integer, sequence_ticket_number, server_default=sequence_ticket_number.next_value(), autoincrement=True, nullable=False)
    Alex Grönholm
    @agronholm
    can you find such a thing in the documentation? https://www.postgresql.org/docs/current/sql-createsequence.html
    Alex Bender
    @alex-bender
    this is not exactly about setting that in SQL, this is about generating sql statement for deletion
    so as far as I can see it's python objects being compiled into sql
    Alex Grönholm
    @agronholm
    that declaration seems a bit odd – isn't it enough to specify the column type and sequence to be used? What are the autoincrement and server_default for?
    Alex Bender
    @alex-bender
    let me check it quickly
    Alex Grönholm
    @agronholm
    why are you pasting these links?
    Alex Bender
    @alex-bender
    you've asked me what is server_default for
    first link answers that
    Alex Grönholm
    @agronholm
    no, I asked why you had that in the column definition
    I know very well what these parameters do
    Alex Bender
    @alex-bender
    sorry, misunderstood your question
    Alex Grönholm
    @agronholm
    https://docs.sqlalchemy.org/en/14/core/defaults.html#sqlalchemy.schema.Sequence <- as you can see from the example, just having the sequence there is enough
    Alex Bender
    @alex-bender
    i see
    the code is legacy, trying to launch tests and droppping whole db is blocked because of problems during sequence deletion
    thanks, gonna try to remove
    Alex Bender
    @alex-bender
    that helped, thanks
    so problem was not at sql level, right?
    if removing this sequence_ticket_number.next_value() part resolves
    Alex Grönholm
    @agronholm
    it was on the table definition level methinks
    Alex Bender
    @alex-bender
    anyways that helped. So even wihout this server_default Sequence will be incrementing, right?
    Alex Grönholm
    @agronholm
    yup
    Alex Bender
    @alex-bender
    nice
    Safa Alfulaij
    @SafaAlfulaij

    Hi all.

    Using ORM.
    I have a O2M relationship that I set to lazy="raise" (addresses in User table).
    Now I want to use the relationship User.addresses in a query:
    result = await async_session.execute(User.addresses.statement)
    But it complains saying AttributeError: 'InstrumentedList' object has no attribute 'statement'

    I don't want to change the lazy so that I don't accidentally call it.

    Federico Caselli
    @CaselIT
    Don't know that that api is. Please see this for details on relationship loading https://docs.sqlalchemy.org/en/14/orm/loading_relationships.html?highlight=relationship+loading
    Safa Alfulaij
    @SafaAlfulaij

    Another question: How to joinedload and selectinload on the same table?
    Example:
    User - O2M - Addresses
    User - M2O (FK) - Group

    This doesn't work:
    select(User).options(joinedload(User.group).selectinload(User.addresses))

    Alex Grönholm
    @agronholm
    @SafaAlfulaij have you tried giving them as separate arguments to options()?
    chaining them indicates that you somehow want to load the "addresses" relationship in the related Group
    Federico Caselli
    @CaselIT

    select(User).options(joinedload(User.group).selectinload(User.addresses))

    you should not chain them since aggresses is not part of Group. they should be separated by comma, since are both "top level" (of user) select(User).options(joinedload(User.group), selectinload(User.addresses))

    Safa Alfulaij
    @SafaAlfulaij
    Thanks both, figured that after a while.
    I'm coming from Django ORM background, so please be patient with me :)
    Federico Caselli
    @CaselIT
    No problem!
    Will Shamblin
    @wcshamblin
    Hi guys, I have a problem that I'm not sure how to approach.
    I have 3 classes that all share some attributes - (id, entry time, owner, category) and I would like to be able to query them all at once.
    So say I need to search for class where entry time < datetime I could easily retrieve all classes where that would be the case. Not knowing much about sqlalchemy I figured the easiest solution would be an abstract class that would then be used for querying but it seems that is not supported?