Re: [sqlalchemy] attributes.get_history() from mapper extension's before_update()

2011-01-16 Thread Michael Bayer
It's constant throughout the flush until the session.after_flush_postexec 
event, with the exception of foreign key attributes populated by relationships.


On Jan 15, 2011, at 9:37 PM, Kent wrote:

 Is it safe trust attributes.get_history(instance, attrname) from
 mapper extension's before_update()?
 
 I assume this is not reset until later?
 
 Kent
 
 -- 
 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.
 

-- 
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] Pass query with as parameter (avoid creating a method and hardcoding a query)

2011-01-16 Thread Michael Bayer

On Jan 15, 2011, at 10:53 PM, Hector Blanco wrote:

 Hello list...
 
 I would like to allow the users to perform certain queries without me
 (or well... my server) knowing in advance what those queries are going
 to be (without hard-coding the query).
 
 For instance: I have a “Product” class. One of it's fields is
 manufacturer and another is model
 
 class Product(declarativeBase):
def __init__(self):
self.model = 
self.manufacturer = 
 
 I would like the user be able to input an string with a query, such as
 “Product.model != 'foo' or Product.model != 'bar'”
 or:
 Product.model == 'foo'  Product.manufacturer == 'bar'
 
 I have created a little Python module (queryTree) that tokenizes the
 string and generates a tree for that kind of queries. For the last one
 mentioned above, it would be something like:
 
 
   sqlalchemy.and_
 /\
  ====
   / \ /   \
 Product.model   foo  Product.manufacturer   bar
 
 1) The “” string can be converted to (stored as) the sqlalchemy.and_ method
 2) The fields of Product are sqlalchemy.orm.synonym(s). If I pass my
 tree module the class I'm going to perform the query for, it can call
 getattr(cls, model) and get the synonym (I mean: get the
 Product.model synonym itself instead of the “model” string)
 3) Equally, the comparators are get with getattr(Product, __eq__) or
 getattr(Product, __ne__) so I can store in the tree node the
 comparator function instead of the string “==” or “!=”
 
 But when I try to run the query:
 from mylibs.product import Product
 queryString = Product.model == 'foo'  Product.manufacturer == 'bar'
 session.query(Product.Product).filter(queryTree.getQuery(queryString,
 Product.Product))
 
 I get an exception:
  File /home/hbr/Documents/my-cms/backlib/product/ProductManager.py,
 line 62, in getByCustomFilter
retval = 
 Database.session.query(Product.Product).filter(queryTokenizer.getQuery()).all()
  File string, line 1, in lambda
  File 
 /home/hbr/.buildout/eggs/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/query.py,
 line 52, in generate
fn(self, *args[1:], **kw)
  File 
 /home/hbr/.buildout/eggs/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/query.py,
 line 942, in filter
filter() argument must be of type 
 ArgumentError: filter() argument must be of type
 sqlalchemy.sql.ClauseElement or string

Well everything I can see is correct here, so you just have to ensure 
getQuery() is returning the root of your tree (which, if it's an and_(), or a 
x == y, is in fact an instance of ClauseElement).   Don't do anything with 
eval() or strings, keep it as a tokenized structure on your end.  SQLA's job is 
to make it into a string.


 
 With some other tests, I've got some other exceptions that made me
 realize that I could possibly modify somehow the nodes of my tree
 until getting something that is accepted by MySQL as a valid query,
 but that's kind of cheating... I'd like to use pure SqlAlchemy if
 possible (I trust SqlAlchemy more than my programming skills) :-D

the system you've built to interpret user input into a SQL expression tree 
should have adequate constraints such that only valid expressions are built in 
the first place.

-- 
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: sqlalchemy rocks my socks off!

2011-01-16 Thread Jan Müller
+1

On Jan 15, 9:58 am, Eric Ongerth ericonge...@gmail.com wrote:
 +1

 On Jan 13, 5:08 pm, rdlowrey rdlow...@gmail.com wrote:







  To Michael Bayer: sqlalchemy simplifies my life every day and makes me
  vastly more productive! Many 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.



[sqlalchemy] how to use version_id_col

2011-01-16 Thread Jan Mueller

Hi everybody,

help...

i need optimistic locking for some concurrently edited entities.
I am experiencing some problems with the version_id_col feature. I 
wanted to use it with my pylons application, but it does not work at all.
I use sqlalchemy 0.6.4 with sqlite (for developement purposes). My 
pylons app is fully functional except for the version_id_col feature. 
Here is my code in addition to my declarative entity classes:


updated_at = Column(DateTime(), nullable=False, default=datetime.now)
__mapper_args__ = {
'version_id_col': updated_at,
'version_id_generator': lambda v:datetime.now()
}

I read in the changes, that in this version the behavior of 
version_id_col was changed. You can not set the version_id_col 
manually!? If you do so, the value you set will be saved to the db... 
and thats exactly what happens, but how can i change this behavior? I 
guess in older versions it was possible to preserve the version through 
an hidden input field?!
How can i use this feature, when the objects of the corresponding entity 
are going to be detached from the unit of work after every http request?


Please help me...

Greetings
Jan

--
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] Pass query with as parameter (avoid creating a method and hardcoding a query)

2011-01-16 Thread Hector Blanco
Thanks for your help! It was key knowing that I was going in the right
direction.

The problem was that I'm stup... erm... I mean... erm... that I made a
bad mistake (beginner's one)...

I was getting the comparator for the Product class: (getattr(Product,
__eq__)) instead of the comparator for the field/synonym (if I
wanted to check for model == 'foo', I needed to get:
getattr(Product.model, __eq__).

Yey!! It works!

Thank you so much!!

2011/1/16 Michael Bayer mike...@zzzcomputing.com:

 On Jan 15, 2011, at 10:53 PM, Hector Blanco wrote:

 Hello list...

 I would like to allow the users to perform certain queries without me
 (or well... my server) knowing in advance what those queries are going
 to be (without hard-coding the query).

 For instance: I have a “Product” class. One of it's fields is
 manufacturer and another is model

 class Product(declarativeBase):
        def __init__(self):
                self.model = 
                self.manufacturer = 

 I would like the user be able to input an string with a query, such as
 “Product.model != 'foo' or Product.model != 'bar'”
 or:
 Product.model == 'foo'  Product.manufacturer == 'bar'

 I have created a little Python module (queryTree) that tokenizes the
 string and generates a tree for that kind of queries. For the last one
 mentioned above, it would be something like:


                   sqlalchemy.and_
             /                        \
          ==                            ==
   /             \             /               \
 Product.model   foo  Product.manufacturer   bar

 1) The “” string can be converted to (stored as) the sqlalchemy.and_ method
 2) The fields of Product are sqlalchemy.orm.synonym(s). If I pass my
 tree module the class I'm going to perform the query for, it can call
 getattr(cls, model) and get the synonym (I mean: get the
 Product.model synonym itself instead of the “model” string)
 3) Equally, the comparators are get with getattr(Product, __eq__) or
 getattr(Product, __ne__) so I can store in the tree node the
 comparator function instead of the string “==” or “!=”

 But when I try to run the query:
 from mylibs.product import Product
 queryString = Product.model == 'foo'  Product.manufacturer == 'bar'
 session.query(Product.Product).filter(queryTree.getQuery(queryString,
 Product.Product))

 I get an exception:
  File /home/hbr/Documents/my-cms/backlib/product/ProductManager.py,
 line 62, in getByCustomFilter
    retval = 
 Database.session.query(Product.Product).filter(queryTokenizer.getQuery()).all()
  File string, line 1, in lambda
  File 
 /home/hbr/.buildout/eggs/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/query.py,
 line 52, in generate
    fn(self, *args[1:], **kw)
  File 
 /home/hbr/.buildout/eggs/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/query.py,
 line 942, in filter
    filter() argument must be of type 
 ArgumentError: filter() argument must be of type
 sqlalchemy.sql.ClauseElement or string

 Well everything I can see is correct here, so you just have to ensure 
 getQuery() is returning the root of your tree (which, if it's an and_(), or 
 a x == y, is in fact an instance of ClauseElement).   Don't do anything 
 with eval() or strings, keep it as a tokenized structure on your end.  SQLA's 
 job is to make it into a string.



 With some other tests, I've got some other exceptions that made me
 realize that I could possibly modify somehow the nodes of my tree
 until getting something that is accepted by MySQL as a valid query,
 but that's kind of cheating... I'd like to use pure SqlAlchemy if
 possible (I trust SqlAlchemy more than my programming skills) :-D

 the system you've built to interpret user input into a SQL expression tree 
 should have adequate constraints such that only valid expressions are built 
 in the first place.

 --
 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.



-- 
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] Pass query with as parameter (avoid creating a method and hardcoding a query)

2011-01-16 Thread Tamás Bajusz
Is your work available, or do you plan to put it public somewhere?


On Sun, Jan 16, 2011 at 7:53 PM, Hector Blanco white.li...@gmail.com wrote:
 Thanks for your help! It was key knowing that I was going in the right
 direction.

 The problem was that I'm stup... erm... I mean... erm... that I made a
 bad mistake (beginner's one)...

 I was getting the comparator for the Product class: (getattr(Product,
 __eq__)) instead of the comparator for the field/synonym (if I
 wanted to check for model == 'foo', I needed to get:
 getattr(Product.model, __eq__).

 Yey!! It works!

 Thank you so much!!

 2011/1/16 Michael Bayer mike...@zzzcomputing.com:

 On Jan 15, 2011, at 10:53 PM, Hector Blanco wrote:

 Hello list...

 I would like to allow the users to perform certain queries without me
 (or well... my server) knowing in advance what those queries are going
 to be (without hard-coding the query).

 For instance: I have a “Product” class. One of it's fields is
 manufacturer and another is model

 class Product(declarativeBase):
        def __init__(self):
                self.model = 
                self.manufacturer = 

 I would like the user be able to input an string with a query, such as
 “Product.model != 'foo' or Product.model != 'bar'”
 or:
 Product.model == 'foo'  Product.manufacturer == 'bar'

 I have created a little Python module (queryTree) that tokenizes the
 string and generates a tree for that kind of queries. For the last one
 mentioned above, it would be something like:


                   sqlalchemy.and_
             /                        \
          ==                            ==
   /             \             /               \
 Product.model   foo  Product.manufacturer   bar

 1) The “” string can be converted to (stored as) the sqlalchemy.and_ 
 method
 2) The fields of Product are sqlalchemy.orm.synonym(s). If I pass my
 tree module the class I'm going to perform the query for, it can call
 getattr(cls, model) and get the synonym (I mean: get the
 Product.model synonym itself instead of the “model” string)
 3) Equally, the comparators are get with getattr(Product, __eq__) or
 getattr(Product, __ne__) so I can store in the tree node the
 comparator function instead of the string “==” or “!=”

 But when I try to run the query:
 from mylibs.product import Product
 queryString = Product.model == 'foo'  Product.manufacturer == 'bar'
 session.query(Product.Product).filter(queryTree.getQuery(queryString,
 Product.Product))

 I get an exception:
  File /home/hbr/Documents/my-cms/backlib/product/ProductManager.py,
 line 62, in getByCustomFilter
    retval = 
 Database.session.query(Product.Product).filter(queryTokenizer.getQuery()).all()
  File string, line 1, in lambda
  File 
 /home/hbr/.buildout/eggs/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/query.py,
 line 52, in generate
    fn(self, *args[1:], **kw)
  File 
 /home/hbr/.buildout/eggs/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/orm/query.py,
 line 942, in filter
    filter() argument must be of type 
 ArgumentError: filter() argument must be of type
 sqlalchemy.sql.ClauseElement or string

 Well everything I can see is correct here, so you just have to ensure 
 getQuery() is returning the root of your tree (which, if it's an and_(), 
 or a x == y, is in fact an instance of ClauseElement).   Don't do anything 
 with eval() or strings, keep it as a tokenized structure on your end.  
 SQLA's job is to make it into a string.



 With some other tests, I've got some other exceptions that made me
 realize that I could possibly modify somehow the nodes of my tree
 until getting something that is accepted by MySQL as a valid query,
 but that's kind of cheating... I'd like to use pure SqlAlchemy if
 possible (I trust SqlAlchemy more than my programming skills) :-D

 the system you've built to interpret user input into a SQL expression tree 
 should have adequate constraints such that only valid expressions are built 
 in the first place.

 --
 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.



 --
 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.



-- 
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 

Re: [sqlalchemy] how to use version_id_col

2011-01-16 Thread Michael Bayer

On Jan 16, 2011, at 1:20 PM, Jan Mueller wrote:

 Hi everybody,
 
 help...
 
 i need optimistic locking for some concurrently edited entities.
 I am experiencing some problems with the version_id_col feature. I wanted 
 to use it with my pylons application, but it does not work at all.
 I use sqlalchemy 0.6.4 with sqlite (for developement purposes). My pylons app 
 is fully functional except for the version_id_col feature. Here is my code in 
 addition to my declarative entity classes:
 
 updated_at = Column(DateTime(), nullable=False, default=datetime.now)
 __mapper_args__ = {
'version_id_col': updated_at,
'version_id_generator': lambda v:datetime.now()
}
 
 I read in the changes, that in this version the behavior of version_id_col 
 was changed. You can not set the version_id_col manually!?

The enhancement in 0.6.4 is that the value of version_id_col *can* be changed 
manually.  This was not possible prior to 0.6.4 - whatever value would be 
placed there would be overwritten on flush.

 If you do so, the value you set will be saved to the db... and thats exactly 
 what happens, but how can i change this behavior?

Why would you set the value of a mapped attribute, then expect it not to be 
persisted ?If you have an attribute that you don't want to be persisted, 
don't map it to a database column.

If you'd like some local non-mapped attribute to have a default value of that 
of your version col, use a descriptor that saves a local value, if not present 
returns the mapped one.

class MyClass(object):

@property
 def my_version_id(self):
 return getattr(self, 'local_version_id', self.version_id)

@my_version_id.setter
def my_version_id(self, value):
 self.local_version_id = value


 I guess in older versions it was possible to preserve the version through an 
 hidden input field?!

I'm not sure what a hidden input field is in the context of generic Python 
objects, but the descriptor example above might be what you're looking for.

 How can i use this feature, when the objects of the corresponding entity are 
 going to be detached from the unit of work after every http request?

When the object is detached, whatever value was already present for version_id 
remains on the object, unaffected, until you change it, or re-attach and 
persist a new version of the object's state.The feature applies to how 
the object is persisted (as does optimistic locking in general) so by 
definition has nothing to do when the object is detached.


-- 
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] Get python type from sqlalchemy.orm.synonym

2011-01-16 Thread Hector Blanco
Hello everyone!

I have created a little module that generates a sqlalchemy query from
an string (yeah, I needed some help:
http://groups.google.com/group/sqlalchemy/browse_thread/thread/6ea3241b1c653444
)

At certain point, I check the type of the field I'm filtering
by creating an instance of the class I'm querying, getting the
contents of said field and checking its type.

I create the instance with cls() (instantiate the class without
passing any parameter to the constructor). That works fine... as long
as I don't need to pass any parameter to the constructor... otherwise,
I would get:
TypeError: __init__() takes exactly [whatever] arguments (1 given).

The field I want to check is a synonym in the class level. I'd like
to know if there's a way to get the Python type (int, list...) from
that synonym (without needed to create an instance of the class)

Let me explain with an example.

Let's say I have a class Product:

 Product.py --
class Product(declarativeBase):
__tablename__ = products

_id = Column(id, Integer, primary_key=True)
_model = Column(model, String(30))
_number = Column(category, Integer)

def __init__(self):
self.model = 
self.number = 0

def setId(self, id):
self._id = int(id)

def getId(self):
return self._id

def setModel(self, model):
self._model = model

def getModel(self):
return self._model

# [...] more code, more getters, setters [...]

id = sqlalchemy.orm.synonym('_id', descriptor=property(getId, setId))
model = sqlalchemy.orm.synonym('_model',
descriptor=property(getModel, setModel))
number = sqlalchemy.orm.synonym('_number',
descriptor=property(getNumber, 
setNumber))

-

The user can input a query as:
Product.model=='foo'  Product.number=='5'
(number may be an string -quoted, I mean- here)

The idea is that then I can pass that string and the class I want to
get results for to my QueryTokenizer class:
queryTokenizer = QueryTokenizer(queryString, classToQuery)
# class to query is the class object: Product.Product, which is what
# if I do prod = Product.Product() would store in prod an instance of
# the Product class

So a call to queryTokenizer.getQuery() would return, for the query
string detailed above:

sqlalchemy.and_( Product.Product.model.__eq__(foo),
   Product.Product.number__eq__(5))

with number being properly casted to an int()

So I can put that in a method (getByCustomFilter, to call it somehow) and do:

from mylibs.product import Product
# ...
queryTokenizer = QueryTokenizer(queryString, Product.Product)
retval = 
Database.session.query(Product.Product).filter(queryTokenizer.getQuery()).all()


The problem is that, in order to perform that cast, I need to find out
the type of the field I'm filtering for (I need to know that in the
instances of Product, Product.number is an int).
To achieve that, I do the following:
I instantiate the class, get the number field of the *instance*,
check its type (will be int) and cast accordingly (cast '5' to int).
Something like:

--- QueryTokenizer---
# [ . . .]
def clean(self, classToQuery):
instance_of_class = classToQuery() # In the example, this the same as 
doing:
#  instance_of_class 
=Product.Product()
type_in_instances = type(getattr(instance_of_class, number))#Gives 
type 'int'
castedValue = type_in_instances(value_to_check) #From the string 5

 # gives the int 5
# [ . . .]

---

But of course, that only works if the constructor of classToQuery
doesn't require arguments. Otherwise the call classToQuery() gives a
type error.

I would like to know if I can get that int from the class itself
(not from an instance). In the class, if I do (getattr(classToQuery,
number)) I get a sqlalchemy.orm.synonym. I would like to know if
from that I can somehow get type 'int' (what I get when in python I
do type(5), type(0)... )

This is not only done so the user can input number == '5' (I could
force the user to input number==5) but also as a layer of security to
make sure the query is correct and that no weird/insecure stuff is
going on.

Thank you!

-- 
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] Get python type from sqlalchemy.orm.synonym

2011-01-16 Thread Michael Bayer

On Jan 16, 2011, at 4:30 PM, Hector Blanco wrote:

 -
 
 The user can input a query as:
 Product.model=='foo'  Product.number=='5'
 (number may be an string -quoted, I mean- here)

if the user says number == '5' , why not consider that to be a string ?  why 
is casting needed ?  if they want an int, they should type an int, no ?

 
 The problem is that, in order to perform that cast, I need to find out
 the type of the field I'm filtering for (I need to know that in the
 instances of Product, Product.number is an int).

assert isinstance(Product.number.__clause_element__().type, Integer)


-- 
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] Get python type from sqlalchemy.orm.synonym

2011-01-16 Thread Hector Blanco
Thanks for replying so quickly...

 if the user says number == '5' , why not consider that to be a string ?  
 why is casting needed ?  if they want an int, they should type an int, no ?


I don't trust my users :-) I don't think they know what they want,
most of the times :-D


 The problem is that, in order to perform that cast, I need to find out
 the type of the field I'm filtering for (I need to know that in the
 instances of Product, Product.number is an int).

 assert isinstance(Product.number.__clause_element__().type, Integer)



I could use that, yeah... That gives the Sql type the column is using
to be stored in the database, right? (VARCHAR(20), INTEGER...) The
only trouble I may foresee is that some of my classes use custom
types (type decorators,
http://www.sqlalchemy.org/docs/core/types.html#sqlalchemy.types.TypeDecorator
) and some fields are stored as a comma separated string in the
database but in the python instances are lists. I haven't tested it
with that kind of custom types, but if the __clause_element__().type
says TEXT then that may cause some troubles, right?

But still, I think I can use it as a backup remedy if the
instantiation of the class fails.

Thank you!

 --
 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.



-- 
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] Get python type from sqlalchemy.orm.synonym

2011-01-16 Thread Michael Bayer

On Jan 16, 2011, at 5:36 PM, Hector Blanco wrote:

 Thanks for replying so quickly...
 
 if the user says number == '5' , why not consider that to be a string ?  
 why is casting needed ?  if they want an int, they should type an int, no ?
 
 
 I don't trust my users :-) I don't think they know what they want,
 most of the times :-D

if your application is going to be in the business of guessing intent, don't 
underestimate the complexity of that, as well as the confusion it will produce.


 
 
 The problem is that, in order to perform that cast, I need to find out
 the type of the field I'm filtering for (I need to know that in the
 instances of Product, Product.number is an int).
 
 assert isinstance(Product.number.__clause_element__().type, Integer)
 
 
 
 I could use that, yeah... That gives the Sql type the column is using
 to be stored in the database, right? (VARCHAR(20), INTEGER...) The
 only trouble I may foresee is that some of my classes use custom
 types (type decorators,
 http://www.sqlalchemy.org/docs/core/types.html#sqlalchemy.types.TypeDecorator
 )

there's a field on each type, in recent 0.6 versions, called _type_affinity.  
It returns a class in all cases, and is always one of the basic types: Integer, 
String, Text, Float, etc.   works for TypeDecorator as well.




 and some fields are stored as a comma separated string in the
 database but in the python instances are lists. I haven't tested it
 with that kind of custom types, but if the __clause_element__().type
 says TEXT then that may cause some troubles, right?
 
 But still, I think I can use it as a backup remedy if the
 instantiation of the class fails.
 
 Thank you!
 
 --
 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.
 
 
 
 -- 
 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.
 

-- 
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] how to use version_id_col

2011-01-16 Thread Jan Mueller
I switched to 0.6.3 and version_id_col works... just like i expected... 
that's really odd...

i guess i will stay at this version and everything will be fine ;-)

thank you very much.

and sorry for the lacky explanation of my problem.

Greetings
Jan

--
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] how to use version_id_col

2011-01-16 Thread Michael Bayer
if there's a bug in version_id_col I'd really like to know.   I don't 
understand the use case for setting the column explicitly, then having it not 
persist.   


On Jan 16, 2011, at 7:11 PM, Jan Mueller wrote:

 I switched to 0.6.3 and version_id_col works... just like i expected... 
 that's really odd...
 i guess i will stay at this version and everything will be fine ;-)
 
 thank you very much.
 
 and sorry for the lacky explanation of my problem.
 
 Greetings
 Jan
 
 -- 
 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.
 

-- 
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] how to use version_id_col

2011-01-16 Thread Jan Mueller

Ok then i will try to explain it:

I have a pylons web application... and i want to use the entity 
attribute updated_at as a Datetime version_id...
so i modified the entity with the mapper args and put a hidden input 
field in my edit html forms for the updated_at value... in order to 
preserve it... i got this idea from some newsgroup some days ago... i 
don't remember exactly where...
this approach is quite simpler, than saving the state respectively the 
entity object to an http session... or any other smaller server-side 
context... like in jee
another point is... i think this wouldn't be possible with pylons... 
because of the serialization of objects saved to the http session 
object... i remember to have read something like this about pylons...


so if the user commits the form i take all input values and set them at 
an entity object. This entity object is not attached to the unit of work 
(i think it is called like this in sqlalchemy?) but it will get attached 
at the moment, when i call session.merge(item) (at least this is what 
the documentation says)... i only want to clarify this?!


so the behavior i need is, that the manually set version_id is used to 
identify the record in the database table... during the update... and 
with version = 0.6.4 this does not work... maybe it works with an 
extremely complex configuration... but i don't know which one this 
should be...


furthermore it is necessary that the manually set version_id is newly 
generated by version_id_generator for the update statement... because 
the intention of version_id during update is not to be set manually... 
but to be generated over and over again... i cannot think of a scenario 
where this shouldn't be the intended behavior?! because the version_id 
is a completely managed attribute... it doesn't make any sense to really 
set it manually and flush this to the db...


maybe you can clarify in which way the version_id_col should behave? and 
which session configuration has to be used?


i use thread-local sqlalchemy sessions and remove those at the end of 
every request... just like the pylons doc recommends:


Session = scoped_session(sessionmaker(autocommit=False, 
expire_on_commit=False))


i don't know if expire_on_commit has necessarily to be False... i tested 
it with True and False... during 0.6.4 and 0.6.6 and nothing changed.
autocommit is False with default behavior... but i thought... just in 
case ;-)


so ... these are my thoughts about version_id_col ...

it works really fine now... with 0.6.3 ;-)

and thanks for the great orm :)

Greetings
Jan


On 01/17/2011 01:17 AM, Michael Bayer wrote:

if there's a bug in version_id_col I'd really like to know.   I don't 
understand the use case for setting the column explicitly, then having it not 
persist.


On Jan 16, 2011, at 7:11 PM, Jan Mueller wrote:


I switched to 0.6.3 and version_id_col works... just like i expected... that's 
really odd...
i guess i will stay at this version and everything will be fine ;-)

thank you very much.

and sorry for the lacky explanation of my problem.

Greetings
Jan

--
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.




--

Jan Müller
Liebigstr. 66
35392 Gießen

Mobil ::: 0151 54825335
Festnetz ::: 0641 39922885
Google Account ::: jan.marco.muel...@gmail.com
E-Mail ::: j...@it-gen.de
Jabber ::: j...@it-gen.de
Skype ::: jan.mueller1981

--
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] Sqla related talks at pycon

2011-01-16 Thread Domingo Aguilera
Is there going to be sqla talks/tutorial at the 2011 pycon?

-- 
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] passive Query

2011-01-16 Thread Eric Lemoine
Hello

For testing purposed I'd like to do query.all(). query.get() and
query.count() with no actual communication with the DBMS. Is this
possible?

Thanks a lot,

-- 
Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 96
Mail : eric.lemo...@camptocamp.com
http://www.camptocamp.com

-- 
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.