Re: [sqlalchemy] Deleting child object in one-to-many relationship trying to load relationship?

2018-08-03 Thread Mike Bayer
On Fri, Aug 3, 2018 at 3:29 PM, Derek Lambert wrote: > When deleting a child object in a one-to-many relationship retrieved with > the raiseload('*') query option an exception is raised. Adding > passive_deletes=True to the relationship on the child prevents the > exception, but that seems like a

[sqlalchemy] Deleting child object in one-to-many relationship trying to load relationship?

2018-08-03 Thread Derek Lambert
When deleting a child object in a one-to-many relationship retrieved with the raiseload('*') query option an exception is raised. Adding passive_deletes=True to the relationship on the child prevents the exception, but that seems like a hack. I can remove the option from the query, but I'm

Re: [sqlalchemy] Deleting rows from a table where row elements are found in a pandas.DataFrame

2018-01-04 Thread Jevgenij Kusakovskij
I sorted this problem out and, as you predicted, it turned out to be layers upon layers of problems. If you do not mind having a quick look at how I resolved this, I would really appreciate some feedback and a second opinion... I actually missed the main problem initially. It had to do with the

Re: [sqlalchemy] Deleting rows from a table where row elements are found in a pandas.DataFrame

2018-01-03 Thread Jevgenij Kusakovskij
It is a list of dictionaries indeed. I will investigate this issue tomorrow. If something useful comes out or if I have any more questions, I will write back here. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please

Re: [sqlalchemy] Deleting rows from a table where row elements are found in a pandas.DataFrame

2018-01-03 Thread Mike Bayer
On Wed, Jan 3, 2018 at 12:30 PM, Jevgenij Kusakovskij wrote: > Thank you for such a quick response! > > Tried your suggestions, but still getting the same error. > > And could it be caused by some data in the DataFrame being 'odd'? E.g. > Timestamp('2012-05-22 00:00:00')

Re: [sqlalchemy] Deleting rows from a table where row elements are found in a pandas.DataFrame

2018-01-03 Thread Jevgenij Kusakovskij
Thank you for such a quick response! Tried your suggestions, but still getting the same error. And could it be caused by some data in the DataFrame being 'odd'? E.g. Timestamp('2012-05-22 00:00:00') assigned to col2. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper

Re: [sqlalchemy] Deleting rows from a table where row elements are found in a pandas.DataFrame

2018-01-03 Thread Mike Bayer
On Wed, Jan 3, 2018 at 11:21 AM, Jevgenij Kusakovskij wrote: > I feel bad bugging you with questions everyday, but it seems that I get them > answered here... Hope I am not abusing your hospitality. > > I would like to delete multiple rows from a table on a MS SQL Server. The >

[sqlalchemy] Deleting rows from a table where row elements are found in a pandas.DataFrame

2018-01-03 Thread Jevgenij Kusakovskij
I feel bad bugging you with questions everyday, but it seems that I get them answered here... Hope I am not abusing your hospitality. I would like to delete multiple rows from a table on a MS SQL Server. The rows to be deleted are given in a `pandas.DataFrame` object and there can be thousands

Re: [sqlalchemy] Deleting detached objects

2016-12-28 Thread Mike Bayer
Calling session.delete() is equivalent to calling session.add() first. The only downside is if the object represents state that has changed in the database elsewhere, like the row was already deleted or had a primary key change. On Dec 28, 2016 8:18 AM, "Julio César Gázquez" <

[sqlalchemy] Deleting detached objects

2016-12-28 Thread Julio César Gázquez
Hi list. I just noticed that if I retrieve an object, and close the session letting the object in detached state, then I can delete the object from the database using a new session simply issuing session.delete(), without merging it first. SQL Alchemy simply emits the DELETE and that's it,

[sqlalchemy] Deleting object attributes to avoid merge comparison no longer works in 1.0

2015-04-04 Thread Russ
I have some buried-in-the-codebase-since-0.7 upsert code that uses `merge`. In order to avoid certain attributes from being used in the merge comparison, the attributes were deleted using delattr.. The code looks something like this: db_obj = sess.query(obj_type).filter_by(**filters).one() pk

Re: [sqlalchemy] Deleting object attributes to avoid merge comparison no longer works in 1.0

2015-04-04 Thread Mike Bayer
On 4/5/15 12:32 AM, Russ wrote: I have some buried-in-the-codebase-since-0.7 upsert code that uses `merge`. In order to avoid certain attributes from being used in the merge comparison, the attributes were deleted using delattr.. The code looks something like this: db_obj =

[sqlalchemy] Deleting from relationship

2015-02-22 Thread Asad Dhamani
I have a many-to-many relationship in my models. This is what they look like: class Post(db.Model): __tablename__ = 'Posts' id = db.Column(db.Integer, primary_key=True) tags_relationship = db.relationship('Tag', secondary=tags, backref=db. backref('posts', lazy='dynamic')) tags =

[sqlalchemy] deleting many-to-many association records

2014-05-21 Thread George V. Reilly
I've spent time unsuccessfully trying to fix some problems with a many-to-many table and lazy joins. Here's a simplified repro: #!/usr/bin/env python # -*- coding: utf-8 -*- import random from sqlalchemy import create_engine, ForeignKey from sqlalchemy import Column,

Re: [sqlalchemy] deleting from a many-to-many association table

2014-05-21 Thread George V. Reilly
Thanks! I went with Appointment.persons = relationship( 'AppointmentPerson', cascade='delete-orphan, delete, save-update, merge, expunge', lazy=LAZYJOIN) and used the slice notation to empty the InstrumentedList: appt.persons[:] = [] In my real app, I spent

[sqlalchemy] deleting from a many-to-many association table

2014-05-19 Thread George Reilly
(Apologies if this is a dupe. I posted it twice via the GG webpage and it never showed up.) I've spent time unsuccessfully trying to fix some problems with a many-to-many relationship and lazy joins. Here's a simplified repro: #!/usr/bin/env python # -*- coding: utf-8 -*- import

Re: [sqlalchemy] deleting from a many-to-many association table

2014-05-19 Thread Michael Bayer
On May 19, 2014, at 12:07 PM, George Reilly george.v.rei...@gmail.com wrote: The code originally used Appointment.persons = relationship( 'AppointmentPerson', cascade='delete, save-update, merge, expunge', lazy='dynamic') where everything worked, but

[sqlalchemy] Deleting all rows in secondary table when object is deleted?

2012-06-25 Thread Gerald Thibault
I have a m2m relationship of Posts and Categories. A post can be in any number of categories, and a category can have any number of posts. This relation is defined on the Post model: categories = relation(Category, lazy=True, secondary=PostCategory.__table__,

Re: [sqlalchemy] Deleting all rows in secondary table when object is deleted?

2012-06-25 Thread Michael Bayer
this question is arising with unusual frequency in recent weeks, which suggests a shortcoming in the docs. Rather than answering here, I've added what is hopefully a comprehensive answer to the documentation; it would be helpful if you could confirm for me that it answers your question, or if

Re: [sqlalchemy] Deleting all rows in secondary table when object is deleted?

2012-06-25 Thread Gerald Thibault
The documentation is fine, I just get lost in it sometimes because there is so much, and I have a hard time tracking down the specific thing I'm looking for. It turns out I was just overcomplicating things. Once I removed 'cascade' from the ref, everything works as expected. Had I just left

Re: [sqlalchemy] Deleting all rows in secondary table when object is deleted?

2012-06-25 Thread Michael Bayer
well dont worry, that doc is new as of an hour ago, and I dont think that behavior is actually explained anywhere; historically, people tend to not worry about it and it just happens, though there have been stackoverflow questions about it lately. it's better that it's described. On Jun 25,

[sqlalchemy] deleting a sqlite database

2012-02-25 Thread lars van gemerden
Hi all, I looking for a way to delete/empty a sqlite database completely (can be in memory or file). I have tried: - metadata.drop_all(engine); which does not work with cyclic references - solution from http://www.sqlalchemy.org/trac/wiki/UsageRecipes/DropEverything; it requires names of

[sqlalchemy] deleting

2010-04-14 Thread Sebastian Elsner
Hello, I am unsure on how to delete correctly. Lets say I have a query's result, which is a list. del list[5] does not seem to do anything, right? I would always have to do session.delete(list[5])? But what about when I created a mapped object, which is not yet persistent, how would I

Re: [sqlalchemy] deleting

2010-04-14 Thread Alexandre Conrad
2010/4/14 Sebastian Elsner sebast...@risefx.com: I am unsure on how to delete correctly. Lets say I have a query's result, which is a list. del list[5] does not seem to do anything, right? I would always have to do session.delete(list[5])? Correct. del list[5] only delete the instance in

[sqlalchemy] Deleting multiple objects

2009-08-19 Thread thatsanicehatyouhave
Hello, I have several objects from a relation that I'd like to delete. To me, this would be a natural syntax: session.delete(office.users) to delete all of the user objects. I get this error when doing this: raise exc.UnmappedInstanceError(instance)

[sqlalchemy] Deleting from collection (updating a collection?)

2009-04-16 Thread Marcin Krol
Hello, I've got many to many relation: Reservation to Host. In Reservation I've got collection (apparently an instance of InstrumentedList) of hosts. How can I delete element from that collection? That is, I do not need to delete Host per se, just delete reference to it in Reservation.hosts.

[sqlalchemy] Deleting records in a MapperExtension on after_delete

2008-11-26 Thread David Harrison
Hey all, I've got a situation where I have 2 object A and B, and a third object C that has a foreign key reference to both A and B. I can have many C's that map to the same A. Now I've implemented a MapperExtension for C that has an after_delete function, and that function checks to see if the

[sqlalchemy] deleting

2007-11-21 Thread imgrey
Good Day sqlalchemy. I was searching, but didn't found a way to delete records from db not executing selection first. So, how to represent this SQL statement in slqalchemy ORM : DELETE FROM a WHERE b = c ? not it look like this : stuff =

[sqlalchemy] Deleting single association in many-to-many relationship

2007-06-13 Thread David Bolen
This seems like it would be a very common scenario, but it's got me stumped and feeling a bit stupid at the moment - I would appreciate anyone helping to point me in the right direction. I'm using the ORM for a many-to-many relationship, for which over time I need to be able to prune individual

[sqlalchemy] Deleting an object from a database?

2007-03-08 Thread Andrea Gavana
Hi All, at the end, I finally cracked the problem with the tree-structured database with SQLAlchemy. I still have however a problem. I am using a physical database, not an in-memory one. I have declared my Tables as follows: trees = Table('treenodes', metadata,

[sqlalchemy] Deleting an object with assignmapper fails

2007-01-26 Thread Alexandre CONRAD
Hello, I'm using SQLAlchemy 0.3.4. I'm having the following problem when trying to delete an object: client = model.Client.get(1) client mp.models.clients.Client object at 0x1088210 client.delete() Traceback (most recent call last): File console, line 1, in ? File