Re: [sqlalchemy] ColanderAlchemy 0.2a1 released!
Hi Lycovian, you can check Deform: https://pypi.python.org/pypi/deform/ Then use ColanderAlchemy with Deform. I also worked on a DeformAlchemy: https://github.com/stefanofontanelli/DeformAlchemy Unfortunately I have no time to complete it. I used in production but I think it needs more work to be stable. Let me know you need more info/help. 2013/5/7 Lycovian mfwil...@gmail.com Looks interesting. Can you give a concrete use case for this library? I'm looking for something that can automatically generate a user form (HTML) to accept input from arbitrary models. Would this lib help with that? mfw On Friday, April 12, 2013 10:10:45 AM UTC-7, Stefano Fontanelli wrote: Fixed. Thank you for the feedback. I also noticed that 0.2a1 release was hidden. I fixed it and it is visible now. Sorry. S. 2013/4/11 Werner werner...@sfr.fr On 12/04/2013 00:01, Stefano Fontanelli wrote: Hi all, ColanderAlchemy 0.2a1 has been released on PyPi. We are waiting feedbacks to add/remove/change features before reach beta version. You can find changelog here: https://github.com/**stefanofontanelli/** ColanderAlchemy/blob/master/**CHANGELOG.txthttps://github.com/stefanofontanelli/ColanderAlchemy/blob/master/CHANGELOG.txt You can find new doc here: https://colanderalchemy.**readthedocs.org/en/latest/https://colanderalchemy.readthedocs.org/en/latest/ BTW, the colander link on the following page does not work. Werner -- 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+...@**googlegroups.com. To post to this group, send email to sqlal...@googlegroups.com. Visit this group at http://groups.google.com/**group/sqlalchemy?hl=enhttp://groups.google.com/group/sqlalchemy?hl=en . For more options, visit https://groups.google.com/**groups/opt_outhttps://groups.google.com/groups/opt_out . -- 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 group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out. -- 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 group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Re: [sqlalchemy] ColanderAlchemy 0.2a1 released!
Fixed. Thank you for the feedback. I also noticed that 0.2a1 release was hidden. I fixed it and it is visible now. Sorry. S. 2013/4/11 Werner werner.bru...@sfr.fr On 12/04/2013 00:01, Stefano Fontanelli wrote: Hi all, ColanderAlchemy 0.2a1 has been released on PyPi. We are waiting feedbacks to add/remove/change features before reach beta version. You can find changelog here: https://github.com/stefanofontanelli/ColanderAlchemy/blob/master/CHANGELOG.txt You can find new doc here: https://colanderalchemy.readthedocs.org/en/latest/ BTW, the colander link on the following page does not work. Werner -- 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 group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out. -- 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 group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
[sqlalchemy] ColanderAlchemy 0.2a1 released!
Hi all, ColanderAlchemy 0.2a1 has been released on PyPi. We are waiting feedbacks to add/remove/change features before reach beta version. You can find changelog here: https://github.com/stefanofontanelli/ColanderAlchemy/blob/master/CHANGELOG.txt You can find new doc here: https://colanderalchemy.readthedocs.org/en/latest/ Kudos to David Beitey ( https://github.com/davidjb ) that did a great job! Thank you very much. Feedbacks are really appreciated. Stefano. -- 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 group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
[sqlalchemy] RelationshipProperty.info in 0.7.x branch.
Hi Michael, do you plan to backport the RelationshipProperty.info attribute in SQLA 0.7? I read the source code and I found Column.info, but seems there is no 'info' attribute in RelationshipProperty. Best Regards, Stefano. -- Stefano Fontanelli Asidev S.r.l. Viale Rinaldo Piaggio, 32 - 56025 Pontedera (Pisa) Tel. (+39) 333 36 53 294 Fax. (+39) 0587 97 01 20 E-mail: s.fontane...@asidev.com Skype: stefanofontanelli Twitter: @stefontanelli LinkedIn: http://it.linkedin.com/in/stefanofontanelli -- 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 unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Purpose of sqlalchemy.orm.properties.ColumnProperty.info
Hi, I'm working on the new release of ColanderAlchemy ( https://github.com/stefanofontanelli/ColanderAlchemy ) which will use the new SQLA 0.8 inspection API. The new version of CA will use 'info' kwarg which can be specified in both Column and relationship. I found also 'info' kwargs in 'sqlalchemy.orm.properties.ColumnProperty' but it is empty when I specify info as in the example below: class Person(Base): __tablename__ = 'people' id = Column(Integer, primary_key=True) name = Column(Unicode(128), nullable=False) surname = Column(Unicode(128), nullable=False, info={'test': 'column'}) addresses = relationship('Address', info={'test': ' relationship'}) m = inspect(Person) print m.attrs.surname.info -- {} print m.attrs.surname.columns[0].info -- {'test': 'column'} print m.attrs.addresses.info -- {'test': 'relationship'} My questions are simple and n00b :) 1) Did you plan to populate ColumnProperty.info with the content of Column.info? 2) Is access of Column.info the right way to 'read' Column.info specified by the user in declarative example? Best Regards, Stefano. -- Stefano Fontanelli Asidev S.r.l. Viale Rinaldo Piaggio, 32 - 56025 Pontedera (Pisa) Tel. (+39) 333 36 53 294 Fax. (+39) 0587 97 01 20 E-mail: s.fontane...@asidev.com Skype: stefanofontanelli Twitter: @stefontanelli LinkedIn: http://it.linkedin.com/in/stefanofontanelli -- 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 unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Purpose of sqlalchemy.orm.properties.ColumnProperty.info
Il 12/10/12 17.38, Michael Bayer ha scritto: On Oct 12, 2012, at 5:10 AM, Stefano Fontanelli wrote: 2) Is access of Column.info the right way to 'read' Column.info specified by the user in declarative example? if you want to get at the .info on Column then yes, but for your purposes it's probably nice to clean it up as above. Thank you Michael for clarification :) I think the Column.info is the best approach for my needs now, but I will figure out possible use case for the approach you described in the examples. Kind Regards, Stefano. -- Stefano Fontanelli Asidev S.r.l. Viale Rinaldo Piaggio, 32 - 56025 Pontedera (Pisa) Tel. (+39) 333 36 53 294 Fax. (+39) 0587 97 01 20 E-mail: s.fontane...@asidev.com Skype: stefanofontanelli Twitter: @stefontanelli LinkedIn: http://it.linkedin.com/in/stefanofontanelli -- 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 unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] ColanderAlchemy 0.1.0 alpha released.
Hi folks! We released ColanderAlchemy 0.1.0 alpha yesterday. It is an extensible package for autogeneration of Colander schemas that are based on SQLAlchemy mapped classes. For those who do not know 'Colander': docs.pylonsproject.org/projects/colander/en/latest/ A quick view on how ColanderAlchemy works can be found in the docs: http://readthedocs.org/docs/colanderalchemy/en/latest/examples.html ColanderAlchemy is released under MIT license terms and it can be forked on GitHub: https://github.com/stefanofontanelli/ColanderAlchemy. The ColanderAlchemy's official documentation can be found on Read The Docs: http://readthedocs.org/docs/colanderalchemy/en/latest/ You can simply install ColanderAlchemy using PIP: pip install ColanderAlchemy or using SetupTools/Distribute: easy_install ColanderAlchemy The library is in alpha stage, but it works. We are working on test suite and docs. We planned to release final version in the next few weeks. We are open to suggestions and any help is appreciate :) Regards, Stefano. -- Stefano Fontanelli E-mail: s.fontane...@asidev.com Website: http://www.asidev.com Skype: stefanofontanelli Twitter: @stefontanelli LinkedIn: http://www.linkedin.com/in/stefanofontanelli -- 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 unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Best practices for saas application
Il 30/01/12 17.47, Samir ha scritto: Hello, I have an application SaaS with mongodb and I need to change to sqlalchemy using postgresql or mysql. Could you explain why you need to switch from MongoDB to SQLAlchemy? My requirements are: Did you miss something? Regards, Stefano. -- Ing. Stefano Fontanelli Asidev S.r.l. Viale Rinaldo Piaggio, 32 - 56025 Pontedera (Pisa) Tel. (+39) 333 36 53 294 Fax. (+39) 0587 97 01 20 E-mail: s.fontane...@asidev.com Skype: stefanofontanelli -- 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 unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] select count(*)
Il 04/11/11 03.08, Mark Erbaugh ha scritto: On Nov 3, 2011, at 2:54 PM, Stefano Fontanelli wrote: Il 03/11/11 19.18, Mark Erbaugh ha scritto: Using the query object count() method generates a sub-query (as per the docs). The docs say to use func.count to avoid the subquery. func.count seems to require a field object. Is there a way to generate a query that essentially becomes 'select count(*) from table' using the ORM, not the SQL generator? Thanks, Mark Did you try func.count('*')? How would you specify the table you want counted? I trued func.count('table.*') and that didn't work. Check the manual: http://www.sqlalchemy.org/docs/orm/tutorial.html#counting To achieve our simpleSELECTcount(*)FROMtable, we can apply it as: SQL http://www.sqlalchemy.org/docs/orm/tutorial.html# session.query(func.count('*')).select_from(User).scalar() Is that right for you? -- Ing. Stefano Fontanelli Asidev S.r.l. Via Osteria Bianca, 108/A 50053 Empoli (Firenze) Tel. (+39) 333 36 53 294 Fax. (+39) 0571 1 979 978 E-mail: s.fontane...@asidev.com Web: www.asidev.com Skype: stefanofontanelli -- 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 unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] select count(*)
Il 03/11/11 19.18, Mark Erbaugh ha scritto: Using the query object count() method generates a sub-query (as per the docs). The docs say to use func.count to avoid the subquery. func.count seems to require a field object. Is there a way to generate a query that essentially becomes 'select count(*) from table' using the ORM, not the SQL generator? Thanks, Mark Did you try func.count('*')? -- Ing. Stefano Fontanelli Asidev S.r.l. Via Osteria Bianca, 108/A 50053 Empoli (Firenze) Tel. (+39) 333 36 53 294 Fax. (+39) 0571 1 979 978 E-mail: s.fontane...@asidev.com Web: www.asidev.com Skype: stefanofontanelli -- 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 unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] defining foreign keys?
/python2.7/site-packages/sqlalchemy/orm/properties.py, line 1376, in _generate_backref self, mapper)) sqlalchemy.exc.ArgumentError: Error creating backref 'user' on relationship 'User.addresses': property of that name exists on mapper 'Mapper|Address|addresses' =8-- Any insight shared would be greatly appreciated. Thanks. -- 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 unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- Ing. Stefano Fontanelli Asidev S.r.l. Via Osteria Bianca, 108/A 50053 Empoli (Firenze) Tel. (+39) 333 36 53 294 Fax. (+39) 0571 1 979 978 E-mail: s.fontane...@asidev.com Web: www.asidev.com Skype: stefanofontanelli -- 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 unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: Cascade Deletes
Il 09/08/11 02.42, Aviv Giladi ha scritto: Dear Stefano, First of all, thank you. Allow me to express how much I appreciate your time and assistance - you and your colleagues are making the technology world this much better by being so attentive and helpful! Thank you. Therefore I chose the second option - adding the cascade=all, delete-orphan to the backref call. This definitely got rid of the problem, however, now the cascade isn't working - when I delete a Rating object, its ProductsRating and the according ProductsProperty persist. It is all illustrated in the attached script. It is the right behaviour, for 'cascade' setting not for your app :) The 'cascade' is setted up on the OneToMany side, in ProductsRating. In your case, you have: Rating - ProductsRating You can cascade from ProductsRating to Rating (symbol '' identify 'Many' side) not the contrary, unless you use 'single_parent=True'. It is the same behaviour of ONUPDATE and ONDELETE of SQL, the difference is that in SQL you put the setting in FK ('One' side of relationship), in SQLA you put the setting in 'Many' side of relationship. In both case you can propagate updates and deletes from 'Many' side to 'One' side of relationships. Regards, Stefano. -- 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 unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: Cascade Deletes
Il 08/08/11 22.53, Aviv Giladi ha scritto: Dear Stefano, I have been able to create a reproducing project. I am sending it to you directly because I was unable to figure out how to attach the test file to the message board. I will post our findings there once we are done. The included script includes all my models. I have 1 rating object, called Rating, 2 subratings - ProductsRating and CustomerServiceRating, and a subrating property - ProductsProperty, that is assigned to ProductsRating. When you run the code I am attaching as is, you will encounter my issue (InterfaceError exception). However, the odd thing is that the following 2 adjustments to the script fix the problem: 1) deleting the three lines 126, 127 and 128 causes the script to work just fine 2) instead of querying the session for the ProductsProperty, creating it with its c'tor makes the script works as well. I am extremely confused by this. Any help you could give me would be beyond appreciated. Thank you so much, Aviv Hi Aviv. You made a mistake using 'cascade' and your code produces 2 warnings: SAWarning: On Rating.products_rating, delete-orphan cascade is not supported on a many-to-many or many-to-one relationship when single_parent is not set. Set single_parent=True on the relationship(). SAWarning: On Rating.customer_service_rating, delete-orphan cascade is not supported on a many-to-many or many-to-one relationship when single_parent is not set. Set single_parent=True on the relationship(). The problem is 'cascade' setting in the following relationships: products_rating = relationship(ProductsRating, cascade=all, delete-orphan, backref=backref(rating, uselist=False)) customer_service_rating = relationship(CustomerServiceRating, cascade=all, delete-orphan, backref=backref(rating, uselist=False)) you cannot set 'cascade' in ManyToMany and ManyToOne relationships, to do that you must specify 'single_parent=True'. Check the docs to understand the usage of 'single_parent'. Otherwise use 'cascade' as follow: products_rating = relationship(ProductsRating, backref=backref(rating, cascade=all, delete-orphan, uselist=False)) customer_service_rating = relationship(CustomerServiceRating, backref=backref(rating, cascade=all, delete-orphan, uselist=False)) I don't know the meaning of you model for that reason you must choose the right solution. I attached your script. I fixed it and SQLA doesn't give me any InterfaceError. HINT: when you use the declarative SQLA you don't need to define __init__ function in your entities. The default __init__ is often enough. It is needed when you want a custom behaviour. Regards, Stefano. PS: you are using Pyramid! Great project! PS2: I send this message in ML to help other users in the future. -- Ing. Stefano Fontanelli Asidev S.r.l. Via Osteria Bianca, 108/A 50053 Empoli (Firenze) Tel. (+39) 333 36 53 294 Fax. (+39) 0571 1 979 978 E-mail: s.fontane...@asidev.com Web: www.asidev.com Skype: stefanofontanelli -- 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 unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. import transaction from sqlalchemy import create_engine from sqlalchemy import * from sqlalchemy.orm import backref from sqlalchemy.orm import relationship from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import scoped_session from sqlalchemy.orm import sessionmaker from zope.sqlalchemy import ZopeTransactionExtension import datetime import random import string DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension())) Base = declarative_base() #describes a business class Business(Base): __tablename__ = 'tbl_businesses' id = Column(Integer, primary_key=True) short_name = Column(Unicode(255), unique=True) name = Column(Unicode(255)) city = Column(Unicode(64)) state = Column(Unicode(8)) ratings = relationship(Rating, backref=business) def __init__(self, short_name, name, city, state): self.short_name = short_name self.name = name self.city = city self.state = state #desribes a user in the system class User(Base): __tablename__ = 'tbl_users' id = Column(Integer, primary_key=True) first_name = Column(Unicode(32)) last_name = Column(Unicode(32)) email = Column(Unicode(64), unique=True) gender = Column(Boolean) is_valid = Column(Boolean) created = Column(DateTime, default=datetime.datetime.utcnow) ratings = relationship(Rating, backref=user) def __init__(self, first_name, last_name, email, gender): self.first_name = first_name self.last_name = last_name self.email = email if gender == male: self.gender = True else: self.gender = False self.is_valid = False #describes a type of user, such as business owner
Re: [sqlalchemy] Re: Cascade Deletes
Il 07/08/11 00.35, Aviv Giladi ha scritto: Everything works great when I create and assign all 3 subratings to the rating object before I add it to the session. However, I need to be able to create a Rating that only has 1 or 2 subratings, and the other subratings absent. When I do that, SQLAlchemy tells me: InterfaceError: (InterfaceError) Error binding parameter 0 - probably unsupported type. u'SELECT SubRating2.id AS subrating2_id \nFROM subratings2 \nWHERE subrating2.id = ?' (symbol 'NEVER_SET,) The above error is when I set Ratings's subrating1 and subrating3, but not subrating2. How do I avoid this error? I think the error is somewhere else in your application code. The model works as you can check in the attached test. Regards, Stefano. -- Ing. Stefano Fontanelli Asidev S.r.l. Via Osteria Bianca, 108/A 50053 Empoli (Firenze) Tel. (+39) 333 36 53 294 Fax. (+39) 0571 1 979 978 E-mail: s.fontane...@asidev.com Web: www.asidev.com Skype: stefanofontanelli -- 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 unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. from sqlalchemy import * from sqlalchemy.orm import backref from sqlalchemy.orm import relationship from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class SubRating1(Base): __tablename__ = 'subratings1' id = Column(Integer, primary_key=True) name = Column(Unicode(32), unique=True) class SubRating2(Base): __tablename__ = 'subratings2' id = Column(Integer, primary_key=True) name = Column(Unicode(32), unique=True) class SubRating3(Base): __tablename__ = 'subratings3' id = Column(Integer, primary_key=True) name = Column(Unicode(32), unique=True) class Rating(Base): __tablename__ = 'ratings' id = Column(Integer, primary_key=True) name = Column(Unicode(32), unique=True) subrating1_id = Column(Integer, ForeignKey('subratings1.id')) subrating1 = relationship(SubRating1, backref=backref(rating, cascade=all, delete-orphan, uselist=False)) subrating2_id = Column(Integer, ForeignKey('subratings2.id')) subrating2 = relationship(SubRating2, backref=backref(rating, cascade=all, delete-orphan, uselist=False)) subrating3_id = Column(Integer, ForeignKey('subratings3.id')) subrating3 = relationship(SubRating3, backref=backref(rating, cascade=all, delete-orphan, uselist=False)) if __name__ == '__main__': from sqlalchemy import create_engine from sqlalchemy.orm import scoped_session from sqlalchemy.orm import sessionmaker engine = create_engine('sqlite:///', echo=True) Base.metadata.create_all(engine) session = scoped_session(sessionmaker()) session.configure(bind=engine) rating = Rating(name=u'My First Rating') session.add(rating) session.flush() assert rating.subrating1 == None assert rating.subrating2 == None assert rating.subrating3 == None session.commit() subrating1 = SubRating1(name=u'My First SubRating1') rating.subrating1 = subrating1 assert rating.subrating1 == subrating1 assert rating.subrating2 == None assert rating.subrating3 == None assert subrating1.rating == rating session.flush() session.commit() subrating3 = SubRating3(name=u'My First SubRating3') rating.subrating3 = subrating3 assert rating.subrating1 == subrating1 assert subrating1.rating == rating assert rating.subrating2 == None assert rating.subrating3 == subrating3 assert subrating3.rating == rating session.flush() session.commit() $ python test.py 2011-08-07 15:48:54,697 INFO sqlalchemy.engine.base.Engine PRAGMA table_info(subratings3) 2011-08-07 15:48:54,697 INFO sqlalchemy.engine.base.Engine () 2011-08-07 15:48:54,698 INFO sqlalchemy.engine.base.Engine PRAGMA table_info(subratings2) 2011-08-07 15:48:54,698 INFO sqlalchemy.engine.base.Engine () 2011-08-07 15:48:54,698 INFO sqlalchemy.engine.base.Engine PRAGMA table_info(subratings1) 2011-08-07 15:48:54,698 INFO sqlalchemy.engine.base.Engine () 2011-08-07 15:48:54,698 INFO sqlalchemy.engine.base.Engine PRAGMA table_info(ratings) 2011-08-07 15:48:54,698 INFO sqlalchemy.engine.base.Engine () 2011-08-07 15:48:54,699 INFO sqlalchemy.engine.base.Engine CREATE TABLE subratings3 ( id INTEGER NOT NULL, name VARCHAR(32), PRIMARY KEY (id), UNIQUE (name) ) 2011-08-07 15:48:54,699 INFO
Re: [sqlalchemy] Re: Cascade Deletes
Il 07/08/11 20.08, Aviv Giladi ha scritto: I see. Where can I start looking for such an error? What could possibly be causing this? I'm sorry but I cannot help you without your code... not a similar code but THE code which produce that error. Regards, Stefano. -- Ing. Stefano Fontanelli Asidev S.r.l. Via Osteria Bianca, 108/A 50053 Empoli (Firenze) Tel. (+39) 333 36 53 294 Fax. (+39) 0571 1 979 978 E-mail: s.fontane...@asidev.com Web: www.asidev.com Skype: stefanofontanelli -- 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 unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Re: Cascade Deletes
Il 06/08/11 00.32, Aviv Giladi ha scritto: Hi Stefano, I create and add a Rating and Subrating (both end up in the DB no problem). Then, I call session.delete(rating_obj) and commit it. I look at the DB, and the Rating is gone, but the SubRating is still there. The DB shows that the Rating has the correct Subrating's ID.. Hi Aviv, I attached the code you sent me. I move 'cascade' as I told you and everything works. See the log that I pasted at the bottom of the script. -- Ing. Stefano Fontanelli Asidev S.r.l. Via Osteria Bianca, 108/A 50053 Empoli (Firenze) Tel. (+39) 333 36 53 294 Fax. (+39) 0571 1 979 978 E-mail: s.fontane...@asidev.com Web: www.asidev.com Skype: stefanofontanelli -- 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 unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. from sqlalchemy import * from sqlalchemy.orm import backref from sqlalchemy.orm import relationship from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() subrating_subratingproperty = Table('subrating_subratingproperty_association', Base.metadata, Column('subrating_id', Integer, ForeignKey('subratings.id')), Column('subrating_property_id', Integer, ForeignKey('subrating_properties.id') )) class SubRatingProperty(Base): __tablename__ = 'subrating_properties' id = Column(Integer, primary_key=True) name = Column(Unicode(32), unique=True) subratings = relationship(SubRating, secondary=subrating_subratingproperty, backref=subrating_properties) class Rating(Base): __tablename__ = 'ratings' id = Column(Integer, primary_key=True) name = Column(Unicode(32), unique=True) subrating_id = Column(Integer, ForeignKey('subratings.id')) subrating = relationship(SubRating, cascade=all, delete-orphan, backref=backref(rating, uselist=False)) class SubRating(Base): __tablename__ = 'subratings' id = Column(Integer, primary_key=True) name = Column(Unicode(32), unique=True) if __name__ == '__main__': from sqlalchemy import create_engine from sqlalchemy.orm import scoped_session from sqlalchemy.orm import sessionmaker engine = create_engine('sqlite:///', echo=True) Base.metadata.create_all(engine) session = scoped_session(sessionmaker()) session.configure(bind=engine) subrating = SubRating(name=u'My First Subrating') rating = Rating(name=u'My First Rating', subrating=subrating) session.add(rating) session.flush() assert rating.subrating != None assert subrating.rating != None session.commit() assert rating.subrating == subrating assert subrating.rating == rating rating = session.query(Rating).first() session.delete(rating) session.flush() session.commit() assert session.query(Rating).all() == [] assert session.query(SubRating).all() == [] $ python test.py 2011-08-06 12:13:02,959 INFO sqlalchemy.engine.base.Engine PRAGMA table_info(subratings) 2011-08-06 12:13:02,959 INFO sqlalchemy.engine.base.Engine () 2011-08-06 12:13:02,960 INFO sqlalchemy.engine.base.Engine PRAGMA table_info(subrating_properties) 2011-08-06 12:13:02,960 INFO sqlalchemy.engine.base.Engine () 2011-08-06 12:13:02,960 INFO sqlalchemy.engine.base.Engine PRAGMA table_info(ratings) 2011-08-06 12:13:02,960 INFO sqlalchemy.engine.base.Engine () 2011-08-06 12:13:02,960 INFO sqlalchemy.engine.base.Engine PRAGMA table_info(subrating_subratingproperty_association) 2011-08-06 12:13:02,960 INFO sqlalchemy.engine.base.Engine () 2011-08-06 12:13:02,961 INFO sqlalchemy.engine.base.Engine CREATE TABLE subratings ( id INTEGER NOT NULL, name VARCHAR(32), PRIMARY KEY (id), UNIQUE (name) ) 2011-08-06 12:13:02,961 INFO sqlalchemy.engine.base.Engine () 2011-08-06 12:13:02,961 INFO sqlalchemy.engine.base.Engine COMMIT 2011-08-06 12:13:02,962 INFO sqlalchemy.engine.base.Engine CREATE TABLE subrating_properties ( id INTEGER NOT NULL, name VARCHAR(32), PRIMARY KEY (id), UNIQUE (name) ) 2011-08-06 12:13:02,962 INFO sqlalchemy.engine.base.Engine () 2011-08-06 12:13:02,962 INFO sqlalchemy.engine.base.Engine COMMIT 2011-08-06 12:13:02,962 INFO sqlalchemy.engine.base.Engine CREATE TABLE ratings ( id INTEGER NOT NULL, name VARCHAR(32), subrating_id INTEGER, PRIMARY KEY (id), UNIQUE (name), FOREIGN KEY(subrating_id
Re: [sqlalchemy] Re: Cascade Deletes
Il 04/08/11 21.27, Aviv Giladi ha scritto: Hey, Tried adding cascade to Rating's backref call like so: subrating = relationship(SubRating, backref=backref(rating, cascade=all, delete-orphan uselist=False)) This unfortunately doesn't work - when I delete a Rating, the according Subratings are NOT removed. What am I doing wrong? (Testing with SQLite) Are you sure about the position of 'cascade' keyword? I think the right way to do that could be: subrating = relationship(SubRating, cascade=all, delete-orphan, backref=backref(rating, uselist=False)) Regards, Stefano. -- 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 unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Default values
Il 05/08/11 19.29, Mark Erbaugh ha scritto: In a declaratively created table, is there an automatic way to get a new instance of the class object to be populated with values specified in a 'default' clause? i.e. class MyTable(Base): __tablename__ = 'table' name = Column(String, default='new name') ... newRow = MyTable() is there a way to have newRow.name automatically have the value 'new name' before it is committed to the database? The best I've been able to come up with so far is to use a 'CONSTANT' in the default clause and use that same CONSTANT to initialize the field in the class' __init__, but this doesn't seem very DRY. Or, maybe is this the wrong question? Maybe I'm trying to do things the wrong way. I'm trying to use mostly the same code add a new row or edit an existing row. If the user is adding a record, I create a new instance of the class and use the add/edit screen to edit the data. If the user is editing an existing row, I retrieve the row, then use the add/edit screen with it. Thanks, Mark Hi Mark, to fill with defaults you can do: newRow = MyTable() session.add(newRow) session.flush() print newRow.name 'print newRow.name' will display 'new name' To use the same code for create/update I suggest you to use session.merge: http://www.sqlalchemy.org/docs/orm/session.html#merging Regards, Stefano. -- 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 unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Re: Cascade Deletes
Il 05/08/11 20.38, Aviv Giladi ha scritto: Hey Stefano, I tried that, but when I did, this is the error I got while inserting a new rating: InterfaceError: (InterfaceError) Error binding parameter 0 - probably unsupported type. u'SELECT subratings.id AS subratings_id \nFROM subratings \nWHERE subratings.id = ?' (symbol 'NEVER_SET,) I need the whole code to help you :) I think it is not related with cascade set. Regards, Stefano. -- Ing. Stefano Fontanelli Asidev S.r.l. Via Osteria Bianca, 108/A 50053 Empoli (Firenze) Tel. (+39) 333 36 53 294 Fax. (+39) 0571 1 979 978 E-mail: s.fontane...@asidev.com Web: www.asidev.com Skype: stefanofontanelli -- 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 unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Default values
Il 05/08/11 20.33, Mark Erbaugh ha scritto: On Aug 5, 2011, at 2:00 PM, Stefano Fontanelli wrote: Il 05/08/11 19.29, Mark Erbaugh ha scritto: In a declaratively created table, is there an automatic way to get a new instance of the class object to be populated with values specified in a 'default' clause? i.e. class MyTable(Base): __tablename__ = 'table' name = Column(String, default='new name') ... newRow = MyTable() is there a way to have newRow.name automatically have the value 'new name' before it is committed to the database? The best I've been able to come up with so far is to use a 'CONSTANT' in the default clause and use that same CONSTANT to initialize the field in the class' __init__, but this doesn't seem very DRY. Or, maybe is this the wrong question? Maybe I'm trying to do things the wrong way. I'm trying to use mostly the same code add a new row or edit an existing row. If the user is adding a record, I create a new instance of the class and use the add/edit screen to edit the data. If the user is editing an existing row, I retrieve the row, then use the add/edit screen with it. Thanks, Mark Hi Mark, to fill with defaults you can do: newRow = MyTable() session.add(newRow) session.flush() print newRow.name 'print newRow.name' will display 'new name' To use the same code for create/update I suggest you to use session.merge: http://www.sqlalchemy.org/docs/orm/session.html#merging Stefano, Thanks for the reply. The problem I see with this approach is that I think it actually commits the new row to the database. In the app, it's possible that the user could decide to cancel before inserting the new row. Of course, I could back out the addition, but it seems like it would be better to not insert in the first place. I understand, but why can you not use session.rollback and session.commit? -- Ing. Stefano Fontanelli Asidev S.r.l. Via Osteria Bianca, 108/A 50053 Empoli (Firenze) Tel. (+39) 333 36 53 294 Fax. (+39) 0571 1 979 978 E-mail: s.fontane...@asidev.com Web: www.asidev.com Skype: stefanofontanelli -- 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 unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Re: Cascade Deletes
Il 30/07/11 23.24, Aviv Giladi ha scritto: Sorry, but I am really confused. Are you guys saying that on SQLite for example, cascade deletes don't work at all? Or do they work, but are less efficient? ONUPDATE/ONDELETE cascade - SQL expression: on SQLite and MySQL MyISAM doesn't work at all. Michael told you that you can reach the same result using the SQLA's relationship option: cascade='all, delete-orphan' This approach is less efficient because delete actions are performed by mapper at the application layer instead of the database: relationship collection objects must be loaded into memory then deleted. Regards, Stefano. -- Ing. Stefano Fontanelli Asidev S.r.l. Via Osteria Bianca, 108/A 50053 Empoli (Firenze) Tel. (+39) 333 36 53 294 Fax. (+39) 0571 1 979 978 E-mail: s.fontane...@asidev.com Web: www.asidev.com Skype: stefanofontanelli -- 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 unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Question about @validates decorator
Il 28/07/11 21.17, Michael Bayer ha scritto: h well there's not a public API for that. Right now (and with no immediate plans to change it) the function should have an attribute called __sa_validators__ which is a list of attribute names.Ultimately there are attribute events assigned though the event API doesn't have a documented introspection interface (yet) either. Yes, I read the code of 'validates' decorator function and I found '__sa_validators__'. About attribute events... I will read the code next weekend. My hope? The existence of a public API :) It is not a problem... Are you interested in a patch? Thank you for the great support. Regards, Stefano. -- 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 unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Question about @validates decorator
Hi folks, I'm working on a project which uses SQLAlchemy as ORM layer and I have a question about @validates decorator. How can I get a list of functions (in each entity of my model) that are decorated using sqlalchemy.orm.validates decorator? Regards, Stefano. -- 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 unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Re: Cascade Deletes
Il 28/07/11 01.15, Aviv Giladi ha scritto: Hi, I am actually using both MySQL and SQLite (one on the dev machine, one on the server). Does that make a difference? ONDELETE and ONUPDATE don't work on SQLite and MySQL MyISAM. You must change your database to test them. In MySQL you can create your database and tables as InnoDB. Regards, Stefano. -- 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 unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.