If I'm doing a bulk insert of a very large number of rows is it possible to
add only the ones that don't violate unique constraints and log the rest?
Since I'm inserting so many rows I don't do a flush/commit after each one,
instead I let my application batch several hundred at a time then do a
I'm trying to make a custom Enum type, but can't seem to do so. This sample
code shows what I'm trying to do:
class Choice(sqlalchemy.types.TypeDecorator):
impl = sqlalchemy.dialects.postgresql.ENUM
def __init__(self):
# super(Choice, self).__init__('a', 'b', 'c', name='d')
On Postgres, I run tests against a database which require that the tables
already exist. The table definitions in the test db need to be identical to
the table definitions in the dev db (in the test db they should be empty
though).
My development workflow is that I change model classes in my
If I have a parent object with a one to many relationship to children
objects, then when I flush the session I don't see any default values when
I inspect the children. In this example, for the first object I can see
attribute '_sa_instance_state', 'first', and 'parent_pk'. For the second
I'm getting this error with the following code. Unfortunately none of the
code in the stacktrace is my code, it's all SQLAlchemy stuff, so I can't
tell where I'm causing the problem.
Traceback (most recent call last):
File
Also my DBSession is defined like this
DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension
()))
And I've enabled pyramid_tm in my development.ini file for Pyramid.
On Sunday, December 21, 2014 1:09:58 AM UTC+1, alchemy1 wrote:
I'm getting this error with the following
I'm getting this warning from my test code, so I know I'm setting something
up wrong. If I have 10 test methods, I get this warning always on the
second test method. Never any of the other ones. If I switch the order of
test methods around I still get an error on the second method.
SAWarning:
) is not
present in table parent.
'INSERT INTO child (..
On Saturday, December 6, 2014 9:55:10 PM UTC+1, alchemy1 wrote:
I have an object that has a foreign key to another, declared like
@declared_attr
def object_uuid(cls):
return Column(UUID, ForeignKey('object.uuid
I have an object that has a foreign key to another, declared like
@declared_attr
def object_uuid(cls):
return Column(UUID, ForeignKey('object.uuid'), nullable=False)
I then do something like
DBSession.add(object)
DBSession.add(dependent_object)
Where DBSession is declared as
When using ORM, is there a way to update without first selecting an object?
For example, if I am updating a User record's name in the database and I
have its primary key, I'd like to just execute one query and update it
straight away. But in order to do so I must run 2 queries, first to select
In one of the YouTube videos on SQLAlchemy Mike said that some of the large
users of SQLAlchemy prefer to use plain SQLAlchemy instead of SQLAlchemy
ORM. What are the reasons behind that? I'm wondering because I started off
with ORM and though I like it I've been wondering whether I might be
I have these classes, with a one-to-many relationship from User to Thing.
Thing has a composite primary key of the user_uuid and the thing_type.
class User(Base):
...
uuid = Column(UUID, primary_key=True)
things = relationship('Thing')
...
class Thing(Base):
...
I added a Postgres TIMESTAMP column and ran a migration, then realized I
wanted to do TIMESTAMP(timezone=True) so I updated my models then ran
another migration, but the migration files had a 'pass' in the
upgrade/downgrade functions rather than doing anything. I had to revert to
the migration
I've been following the pattern of (in Pyramid webapps) doing DBSession.add
then letting the web framework flush/commit the DBSession at the end of the
web request rather than doing it explicitly.
Are there cases where doing it this way could cause unexpected results, for
example let's say you
/11/2014 04:37 PM, alchemy1 wrote:
I have combined several examples I've found to try to get the
'transactional-style' of unit tests to work, where you roll back the
database after each test. However when I run this, the test fails when
trying to insert the object with DBSession.add
': one}
I'm getting an error:
sqlalchemy.exc.UnboundExecutionError: Could not locate a bind configured on
mapper Mapper|MyModel|models, SQL expression or this Session
Any ideas?
On Tuesday, August 12, 2014 11:44:05 AM UTC+2, alchemy1 wrote:
DBSession is like this (not even sure if I need to do
I have combined several examples I've found to try to get the
'transactional-style' of unit tests to work, where you roll back the
database after each test. However when I run this, the test fails when
trying to insert the object with DBSession.add, complaining that the tables
don't exist. I
I see that in ForeignKey I can use either a string or reference, so
ForeignKey(MyModel.id) or ForeignKey('my_model.id'). Any advantage to using
one or the other? What's the recommended approach?
When using the string way, is it recommended to use the model name like
'MyModel.id' or table name
18 matches
Mail list logo