Giter Site home page Giter Site logo

Cascade Delete Issue about ormar HOT 7 CLOSED

jbertman avatar jbertman commented on May 21, 2024
Cascade Delete Issue

from ormar.

Comments (7)

collerek avatar collerek commented on May 21, 2024 1

Fixed in 0.9.0 by #92

from ormar.

collerek avatar collerek commented on May 21, 2024

That's not the case as ormar uses only core part of the sqlalchemy, so the one to create tables and build selects/inserts etc. So most of the issues for sa won't help you with ormar as they usually refer to orm part (the one that you inherit from base etc.). You need to specifically search for core issues but even this might not help you as ormar is built on top of this.

When you call get or all in ormar you actually get the results back and later you delete this particular instance. If you want to delete without loading there is delete also in QuerySet, i recently updated the docs in this regard.

Will check what's going on with the cascades.

Btw. Did you create the tables with ormar or connect to existing ones? Did you re-create/alter the tables after adding ondelete?

from ormar.

jbertman avatar jbertman commented on May 21, 2024

@collerek I tried to generate a new revision after adding ondelete, but no changes were detected by alembic. I can try to do it from scratch and report back.

EDIT: seems to have resulted in the same thing - let me know if I can provide anything of use.

from ormar.

collerek avatar collerek commented on May 21, 2024

There is something wrong i investigate what exactly. In sqlite it sometimes does not create the flat. Can you check if the database structure in your case includes foreign keys definition? Or just the columns and no relations whatsoever?

I think it's something with the scope/locals/globals during resolution of foreign keys.

from ormar.

jbertman avatar jbertman commented on May 21, 2024

from ormar.

jbertman avatar jbertman commented on May 21, 2024

While not ideal, I solved this manually by adding the constraints to my Alembic script as such (still using the above example):

    op.create_table(
        "projects",
        sa.Column("id", sa.CHAR(36), nullable=False),
        sa.Column("created_date", sa.DateTime(), nullable=True),
        sa.Column("updated_date", sa.DateTime(), nullable=True),
        sa.Column("name", sa.String(length=256), nullable=False),
        # <SNIP>
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "quotes",
        sa.Column("id", sa.CHAR(36), nullable=False),
        sa.Column("created_date", sa.DateTime(), nullable=True),
        sa.Column("updated_date", sa.DateTime(), nullable=True),
        sa.Column("project", sa.CHAR(36), nullable=True),
        # <SNIP>
        sa.PrimaryKeyConstraint("id"),
        sa.ForeignKeyConstraint(
            ["project"], ["projects.id"], ondelete="CASCADE", onupdate="CASCADE"
        ),
    )

That allows everything else to function as normal, and lets the DB take care of cascading the operation (can't speak to support for other backends, but this works for postgres).

from ormar.

collerek avatar collerek commented on May 21, 2024

Yeah, but that how it's supposed to look like out of the box :)

I found the bug it's related to deep-cloning sqlalchemy.Columns, will fix this and release new version soon.

Also will add names to foreign_keys so alembic can clearly identify constraints and not recreate them during consecutive runs.

from ormar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.