Thanks Jonathan. This is a very low traffic application, so not a problem
but I appreciate you mentioning it.
--
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
FWIW: If your application is high-traffic/high-concurrency, depending on
how your transactions are scoped within the code you may want to do the
getcreate or create step that calls `.flush` within an exception block or
savepoint, to catch duplicate inserts.
I've only had to do this on 2 (out
Hi Keith,
Small world!
You have at least 3 options depending on your requirements:
1. Handle it in your own application logic (e.g. make a get_or_create
method) - I tend to prefer this, business rules for create vs. update often
creeps in.
2. Use session.merge
I'm new to SQLAlchemy. Sorry if it shows.
I'm using a MySQL backend. I've set up a declarative_base, defined a table
class, set up a session. I defined a record as a dictionary and added it
successfully to the db with:
incident = Incidents(**record)
session.add(incident)
session.commit()
The
Thanks Mike, indeed, that was the problem. I solved it using an "ad hoc"
copy function. This is the solution that worked for me in case somebody
else incurs in the same mistake I did
def copy_sqla_object(obj, omit_fk=True):
"""Given an SQLAlchemy object, creates a new object (FOR WHICH THE
On Fri, Jul 14, 2017 at 1:24 AM, David Laredo Razo
wrote:
this code is the problem:
>
> new_object = copy.copy(reading)
copy() will copy the _sa_instance_state and prevent the session from
tracking the object correctly.
Correct pattern should be:
new_object =
i did as you instructed me but the error persists.
This is the example code im talking about
Session = sessionmaker()
session = Session()
mapper = inspect(ThermafuserReading)
readings = list()
header = ["hex(id(object))", "is transient", "is pending", "is persistent",
"is detached", "is
On Thu, Jul 13, 2017 at 12:31 AM, David Laredo Razo
wrote:
> Hello, I am using SQLAlchemy version 1.2.0b1
>
>
>
> So far so go, the problem arises when I add readings to the session via
> session.add_all(readings). I only get the last element in my list added,
> e.g.
Hello, I am using SQLAlchemy version 1.2.0b1
I created some mapped objects using the declarative style in SQLAlchemy. I
have a mapping called ThermafuserReading which has a composed primary key
made up of the Time_stamp column which is DateTime and ThermafuserId column
which is an Integer and
I've found that sometimes sqlalchemy inserts objects during
session.commit() not in the order they have been added using session.add()
I've put my code example and the output to the github gist.
https://gist.github.com/vpol/8da4a512308ae351eaf6
My question is similar to this one:
the order in which you put things into session.add() is significant only
within the scope of a certain mapped class, that is, the order that you put
a bunch of Foo() objects into session.add() will be maintained, however a
series of Bar() objects are handled separately.
Between different object
I have a strange error using Python 3.3.0 and SQLAlchemy 0.8.0:
from sqlalchemy import create_engine, Integer, String, Text, Column, Sequence,
DateTime, ForeignKeyfrom sqlalchemy.orm import sessionmaker, relationship,
backreffrom sqlalchemy.ext.declarative import declarative_base
engine =
I think you need to commit your session data.
Em terça-feira, 16 de abril de 2013, Tim Cooijmans escreveu:
I have a strange error using Python 3.3.0 and SQLAlchemy 0.8.0:
from sqlalchemy import create_engine, Integer, String, Text, Column,
Sequence, DateTime, ForeignKeyfrom sqlalchemy.orm
cant reproduce, running with Python 3.3.0 here against 0.8.0 I get the INSERT:
PRAGMA table_info(products)
2013-04-16 16:14:41,019 INFO sqlalchemy.engine.base.Engine ()
2013-04-16 16:14:41,019 INFO sqlalchemy.engine.base.Engine
CREATE TABLE products (
id INTEGER NOT NULL,
name
I tried your same code here I got True.
Em terça-feira, 16 de abril de 2013, Michael Bayer escreveu:
cant reproduce, running with Python 3.3.0 here against 0.8.0 I get the
INSERT:
PRAGMA table_info(products)
2013-04-16 16:14:41,019 INFO sqlalchemy.engine.base.Engine ()
2013-04-16
On Dec 16, 2010, at 12:39 AM, Julian Scheid wrote:
In an application that is heavy on inserts and updates, cProfile
output is dominated by Session.add in which about 45% of time is
spent. Most of that time, in turn, is spent in cascade_iterator (43%).
I can provide more detailed information
In an application that is heavy on inserts and updates, cProfile
output is dominated by Session.add in which about 45% of time is
spent. Most of that time, in turn, is spent in cascade_iterator (43%).
I can provide more detailed information if needed.
The application does aggressive caching of
I'm using session.add() to refresh my objects while working on them,
because I don't want to merge them with the persistent state. But it
appears deletes aren't carrying across to child relations:
$ cat listdelete.py; python listdelete.py
import sqlalchemy as sql
from sqlalchemy import orm
On Jan 30, 2010, at 9:07 AM, avdd wrote:
I'm using session.add() to refresh my objects while working on them,
because I don't want to merge them with the persistent state. But it
appears deletes aren't carrying across to child relations:
this example is too compliated for me to understand
On Jan 30, 2010, at 9:07 AM, avdd wrote:
I'm using session.add() to refresh my objects while working on them,
because I don't want to merge them with the persistent state. But it
appears deletes aren't carrying across to child relations:
in r6711 the save-update cascade operation will
Hello everyone,
I have tested that session.add(changed_sqla_object) in at least one
context (when the object with id of changed_sqla_object already exists
in the db) does issue UPDATE sql query and updates the object in the
database.
However, there's also session.update() method. Help on
hello,
i need to generate a unique number from a table based on the primary
key. i used to lock
the table (with write) and got what i needed. working with the ORM,
though, it seems that
session.add(object) functions just as well. at the time of the
session.add(), the primary key assigned to the
22 matches
Mail list logo