[sqlalchemy] sqlacodegen 1.1.6 released.

2015-05-15 Thread Alex Grönholm
This update only fixes compatibility with SQLAlchemy 1.0. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this

[sqlalchemy] Trouble with AbstractConcreteBase and aliased columns

2015-07-09 Thread Alex Grönholm
The following script no longer works in 1.0.6, but does in 0.9.9: from sqlalchemy.ext.declarative import declarative_base, AbstractConcreteBase from sqlalchemy.ext.declarative.api import declared_attr from sqlalchemy.orm.mapper import configure_mappers from sqlalchemy.orm.session import Session f

Re: [sqlalchemy] Trouble with AbstractConcreteBase and aliased columns

2015-07-09 Thread Alex Grönholm
y="sendMethod") > > @declared_attr > def company_id(self): > return Column(ForeignKey('companies.id')) > > > > On 7/9/15 11:18 AM, Alex Grönholm wrote: > > The following script no longer works in 1.0.6, but does in 0.9.9

Re: [sqlalchemy] Trouble with AbstractConcreteBase and aliased columns

2015-07-09 Thread Alex Grönholm
Thanks for the response! The solution looks too hairy for my tastes, and I can manage with what I currently have. Good to know it's possible though! 10.07.2015, 02:25, Mike Bayer kirjoitti: On 7/9/15 12:17 PM, Alex Grönholm wrote: Thanks. What about my other question? Is it possible to

[sqlalchemy] Rolling back the session in a context manager

2016-07-15 Thread Alex Grönholm
The documentation provides the following example snippet for using sessions within a context manager: @contextmanagerdef session_scope(): """Provide a transactional scope around a series of operations.""" session = Session() try: yield session session.commit() exce

Re: [sqlalchemy] Rolling back the session in a context manager

2016-07-16 Thread Alex Grönholm
15.07.2016, 16:55, Mike Bayer kirjoitti: On 07/15/2016 07:49 AM, Alex Grönholm wrote: The documentation provides the following example snippet for using sessions within a context manager: so, back when I started putting "examples" in those docs, the idea was like, "hey, her

[sqlalchemy] Enum recipe on SQLAlchemy 0.8.0 final

2013-04-10 Thread Alex Grönholm
The following class works on 0.8.0b2 but not 0.8.0 final: > class EnumWrapper(SchemaType, TypeDecorator): > def __init__(self, cls): > kwargs = {'name': cls.__name__.lower()} > self.impl = Enum(*(obj.key for obj in cls.values), **kwargs) > self.wrapped = cls > > d

Re: [sqlalchemy] Enum recipe on SQLAlchemy 0.8.0 final

2013-04-10 Thread Alex Grönholm
10.04.2013 18:06, Michael Bayer kirjoitti: On Apr 10, 2013, at 5:10 AM, Alex Grönholm <mailto:alex.gronh...@nextday.fi>> wrote: The following class works on 0.8.0b2 but not 0.8.0 final: class EnumWrapper(SchemaType, TypeDecorator): def __init__(self, cls):

[sqlalchemy] Announcing new model code generation tool: sqlacodegen

2013-05-17 Thread Alex Grönholm
After a while of trying to fix sqlautocode, I ended up writing a new tool instead. Copypasta from the README: - This is a tool that reads the structure of an existing database and generates the appropriate SQLAlchemy model code, using the declarative

[sqlalchemy] Re: Announcing new model code generation tool: sqlacodegen

2013-05-17 Thread Alex Grönholm
Forgot to add the link: https://pypi.python.org/pypi/sqlacodegen -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post t

Re: [sqlalchemy] Announcing new model code generation tool: sqlacodegen

2013-05-18 Thread Alex Grönholm
18.05.2013 12:35, Chris Withers kirjoitti: On 18/05/2013 01:28, Alex Grönholm wrote: This is a tool that reads the structure of an existing database and generates the appropriate SQLAlchemy model code, using the declarative style if possible. Playing devils advocate to get my head around this

[sqlalchemy] What is polymorphic_on needed for in a joined table inheritance schema?

2013-05-24 Thread Alex Grönholm
I used joined table inheritance in Hibernate and it worked fine without any extra discriminator columns. Why is it necessary in SQLAlchemy? I can understand the need for such a column in single table inheritance, but not joined table. -- You received this message because you are subscribed to t

[sqlalchemy] sqlacodegen 1.1.0 released

2013-05-25 Thread Alex Grönholm
Although it's only been a week since the initial release, I've already added a bunch of new features. Release highlights: - Added automatic detection of joined-table inheritance - Fixed missing class name prefix in primary/secondary joins in relationships - Instead of wildcard import

[sqlalchemy] sqlacodegen 1.1.1 released

2013-06-12 Thread Alex Grönholm
This is a bugfix release. Issues resolved: - Fixed TypeError when inflect could not determine the singular name of a table for a many-to-1 relationship - Fixed _IntegerType, _StringType etc. being rendered instead of proper types on MySQL -- You received this message because yo

[sqlalchemy] sqlacodegen 1.1.2 released

2013-09-01 Thread Alex Grönholm
This is another bugfix release. All reported issues have now been resolved. Changes in this version: - Fixed non-default schema name not being present in __table_args__ (fixes #2) - Fixed self referential foreign key causing column type to not be rendered - Fixed missing "deferrab

Re: [sqlalchemy] Unit testing, mocking and dependency injection with SA Declarative.

2013-09-11 Thread Alex Grönholm
I wrote a blog post on this very topic recently: http://alextechrants.blogspot.fi/2013/08/unit-testing-sqlalchemy-apps.html tiistai, 10. syyskuuta 2013 19.43.35 UTC+3 Toph Burns kirjoitti: > > Could you use an in-memory, sqlite db for your testing? For our > applications, we have an initializ

[sqlalchemy] How do I unregister event listeners?

2013-09-11 Thread Alex Grönholm
I'm trying to test code that listens to session events on all sessions. I can't pin it on any particular session or even sessionmaker due to the architecture of the software (sessions are explicitly instantiated on the fly). All is well except that the listener sticks after the test is done, br

[sqlalchemy] Re: How do I unregister event listeners?

2013-09-11 Thread Alex Grönholm
;after_flush', self.queue_events) File "/home/alex/virtualenv/triancore/lib/python3.3/site-packages/sqlalchemy/event.py", line 76, in remove for tgt in evt_cls._accept_with(target): nose.proxy.TypeError: 'type' object is not iterable keskiviikko, 11. syyskuuta 20

Re: [sqlalchemy] How do I unregister event listeners?

2013-09-11 Thread Alex Grönholm
Thanks for the quick reply. I don't want to use prerelease versions of SQLAlchemy though. Is there any recommended way of doing this in 0.8.2? keskiviikko, 11. syyskuuta 2013 20.40.40 UTC+3 Michael Bayer kirjoitti: > > > On Sep 11, 2013, at 1:16 PM, Alex Grönholm > > > w

Re: [sqlalchemy] How do I unregister event listeners?

2013-09-11 Thread Alex Grönholm
f evt(target): >for listener in my_listeners: > listener(target) > > > > On Sep 11, 2013, at 1:44 PM, Alex Grönholm > > > wrote: > > Thanks for the quick reply. I don't want to use prerelease versions of > SQLAlchemy though. Is there any recommended way

[sqlalchemy] sqlacodegen 1.1.3 released.

2013-12-11 Thread Alex Grönholm
This release fixes compatibility with SQLAlchemy 0.8.3 and onwards. The test suite passes on SQLAlchemy 0.9.0b1 as well. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an ema

[sqlalchemy] How can I use the OVERLAPS operator?

2013-12-17 Thread Alex Grönholm
I would like to check if two date ranges overlap. This is done using the OVERLAPS operator . For example: SELECT (DATE '2001-02-16', DATE '2001-12-21') OVERLAPS (DATE '2001-10-30', DATE '2002-10-30'); How do I do this i

Re: [sqlalchemy] How can I use the OVERLAPS operator?

2013-12-18 Thread Alex Grönholm
Ah, I was completely unaware of tuple_(). That's what I was looking for. Thanks! keskiviikko, 18. joulukuuta 2013 18.31.42 UTC+2 Michael Bayer kirjoitti: > > > On Dec 17, 2013, at 8:39 PM, Alex Grönholm > > > wrote: > > I would like to check if two date ranges ov

[sqlalchemy] sqlacodegen 1.1.4 released.

2014-01-02 Thread Alex Grönholm
This release fixes compatibility with the just released SQLAlchemy 0.9.0 final. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroup

[sqlalchemy] Mutable ARRAY

2014-05-03 Thread Alex Grönholm
There doesn't seem to be a class like MutableDict that provides equivalent functionality for the ARRAY column type. Any particular reason why? I'd like to be able to do .append() and .remove() on an array column. Do I have to roll my own? -- You received this message because you are subscribed

Re: [sqlalchemy] Mutable ARRAY

2014-05-03 Thread Alex Grönholm
03.05.2014 16:04, Michael Bayer kirjoitti: I'd like to provide mutablearray though, so if someone can roll it with some tests it can go right in. I'll look into it. Sent from my iPhone On May 3, 2014, at 9:02 AM, Alex Grönholm <mailto:alex.gronh...@nextday.fi>> wrote:

[sqlalchemy] Encapsulating insert/update logic of mapped classes in the class itself

2014-06-01 Thread Alex Grönholm
This has been a problem for me for years. class DeliveryAddress(Base, Address): ... delivery_method = Column(String) ... @event.listens_for(DeliveryAddress, 'before_insert') def before_insert_deliveryaddress(mapper, connection, target): settings = object_session(target).query(Sett

Re: [sqlalchemy] Encapsulating insert/update logic of mapped classes in the class itself

2014-06-02 Thread Alex Grönholm
> On Jun 2, 2014, at 1:47 AM, Alex Grönholm > wrote: > > > This has been a problem for me for years. > > > > class DeliveryAddress(Base, Address): > > ... > > delivery_method = Column(String) > > ... > > > > @event.listen

Re: [sqlalchemy] Encapsulating insert/update logic of mapped classes in the class itself

2014-06-02 Thread Alex Grönholm
ef before_insert(self, session): #... These are "frameworky" types of hooks that SQLAlchemy would prefer to remain agnostic of, but it provides for you all the components you need to create whatever system of hooks you'd like. On Jun 2, 2014, at 8:04 AM, Alex Grönholm

[sqlalchemy] More than one level of abstract base classes doesn't work

2014-09-04 Thread Alex Grönholm
The following code fails with AttributeError: 'NoneType' object has no attribute 'concrete': from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import AbstractConcreteBase, declarative_base Base = declarative_base() class Document(Base, AbstractConcreteBase)

Re: [sqlalchemy] More than one level of abstract base classes doesn't work

2014-09-05 Thread Alex Grönholm
Thanks. I've filed an issue at Bitbucket. A follow-up question: Why are abstract base classes not present in the declarative class registry? Or is there another way to get all the mapped classes besi

Re: [sqlalchemy] More than one level of abstract base classes doesn't work

2014-09-05 Thread Alex Grönholm
part of it. > > if you want to get every class whether mapped or not, maybe use > Base.__subclasses__() ? > > What’s the use case where you need the abstract base in the decl class > registry? it’s not really something you’d want to refer to in a > relationship(). > &

Re: [sqlalchemy] More than one level of abstract base classes doesn't work

2014-09-05 Thread Alex Grönholm
, type)] perjantai, 5. syyskuuta 2014 17.19.21 UTC+3 Alex Grönholm kirjoitti: > > You're right, I'm dumb. I should've just used __subclasses__ and be done > with it. > The use case is that I have a client-server app and I build a list of all > classes for the cl

Re: [sqlalchemy] More than one level of abstract base classes doesn't work

2014-09-05 Thread Alex Grönholm
Sorry to be asking more questions, but the docs on inheritance don't get into much details on how the properties are supposed to work. The following code produces unexpected results: from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import AbstractConcreteBase,

[sqlalchemy] Vs: Composite Foreign Key with ondelete='CASCADE' does not work on mysql

2011-05-30 Thread Alex Grönholm
It's not clear from your code, but are you using InnoDB or MyISAM? You need to be using InnoDB for foreign keys to work properly. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To

[sqlalchemy] Single table inheritance + join weirdness

2011-11-15 Thread Alex Grönholm
I encountered a little strangeness when joining to a class using single table inheritance. I was wondering why I got no results for one particular query. This was originally encountered with PostgreSQL but was successfully reproduced with SQLite. Is this a bug or a user error? SNI

Re: [sqlalchemy] Single table inheritance + join weirdness

2011-11-16 Thread Alex Grönholm
Yeah my bad, the original query does indeed query for (Z.id, B.name). I had just changed it to A.name to get the printout for the "workaround" query and forgot to change it back before pasting here. If there's something I can do to contribute (not sure I'm qualified to write those tests), do tel

[sqlalchemy] Persisting an object with cascading relationships

2011-11-18 Thread Alex Grönholm
My use case is the following: each SalesItem requires a calcPriceList and a salesPriceList (of type PriceList) attached to it. For that, SalesItem has two fields: calcpricelist_id = Column(BigInteger, ForeignKey(PriceList.id), nullable=False) salespricelist_id = Column(BigInteger, Foreign

Re: [sqlalchemy] Persisting an object with cascading relationships

2011-11-18 Thread Alex Grönholm
How silly of me not to have checked that in the docs. Rather embarrassing really :) Thanks. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/rTk1ea1hvrgJ. To po

[sqlalchemy] Unpickling of model instances fails when using mapped collections

2012-02-15 Thread Alex Grönholm
I'm having trouble unpickling model instances where the class has an attribute-mapped collection: import pickle from sqlalchemy import create_engine, Column, Integer, Unicode, ForeignKey from sqlalchemy.orm import Session, relationship from sqlalchemy.orm.collections import attribute_mapped_coll

[sqlalchemy] Re: Unpickling of model instances fails when using mapped collections

2012-02-16 Thread Alex Grönholm
So basically this comes down the operator.attrgetter not being serializable. I'm wondering why something like this would be serialized at all -- aren't collections part of the class definition? -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To

Re: [sqlalchemy] Re: Unpickling of model instances fails when using mapped collections

2012-02-16 Thread Alex Grönholm
Yup, this is exactly what I did just 2 minutes ago :) -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/Eto2-sirT7wJ. To post to this group, send email to sqlalch

[sqlalchemy] CircularDependencyError with relationships

2012-06-05 Thread Alex Grönholm
I have trouble configuring two relationships from one class to another. The following code should be fairly self-explanatory: from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class Company(Base): __tabl

Re: [sqlalchemy] CircularDependencyError with relationships

2012-06-06 Thread Alex Grönholm
06.06.2012 18:06, Michael Bayer kirjoitti: you need to use the post_update option described at http://docs.sqlalchemy.org/en/rel_0_7/orm/relationships.html#rows-that-point-to-themselves-mutually-dependent-rows . Thanks for the pointer. Problem solved :) On Jun 6, 2012, at 1:15 AM, Alex

[sqlalchemy] Multi-table deletes with PostgreSQL

2016-09-16 Thread Alex Grönholm
I'm attempting to do a multi-table delete against PostgreSQL (psycopg2) with the following query: session.query(ProductionItem).\ filter(Project.id == ProductionItem.project_id, Project.code.in_(projects), ProductionItem.external_id.is_(None)).\

[sqlalchemy] sqlacodegen 2.0.0 released

2018-05-20 Thread Alex Grönholm
After a quiet period of 3 years, I've now made a new major release. This release fixes a huge number of bugs and supports the latest SQLAlchemy and latest Python versions as well. It also adds support for Geoalchemy2. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://