On Oct 11, 5:32 pm, Michael Bayer <[EMAIL PROTECTED]> wrote:
> On Oct 11, 2008, at 8:40 PM, Julian Yap wrote:
> > Hi All,
>
> > According to this change set 
> > -->http://www.sqlalchemy.org/trac/changeset/5054
> > The 'length' argument to all Numeric types has been renamed to
> > 'scale'. 'length' is deprecated and is still accepted with a warning.
>
> > On my workstation, I have SQLAlchemy 0.5.0rc1 whereas on some servers
> > I have 0.4.7p1 (due to Python 2.3).
>
> > Running a script on my workstation spits out the deprecation warnings.
>
> > What would be the best way to re-write my script so it's backwards
> > compatible to 0.4.x and doesn't spit out the deprecation warnings in
> > 0.5.x?
>
> > Here's an example line:
> > model.py:54: SADeprecationWarning: 'length' is deprecated for
> > Numeric.  Use 'scale'.
> >  schema.Column('balance', types.Numeric(precision=20, length=6),
> > nullable=False, default=0.000000),
>
> > I'm thinking perhaps a try block at the start of my model.py script
> > which tests for the SQLAlchemy version?
>
> Two ways to do this.  One is to make a wrapper function around Numeric  
> which does the right thing based on SQLAlchemy version, i.e.
>
> def Numeric(**kwargs):
>     if SQLALCHEMY_4:
>          kwargs['scale'] = kwargs.pop('length', None)
>     return types.Numeric(**kwargs)
>
> The other is just to use the warnings filter to suppress the warning,  
> as described inhttp://www.python.org/doc/2.4.2/lib/warning-
> filter.html .

The wrapper function sounds the best.  That way the bulk of my code
will run the latest version of SQLAlchemy.

How would you implement it?

Here's a code example:
--- Begin model.py ---
from sqlalchemy import schema, types
from sqlalchemy import orm

metadata = schema.MetaData()
customers_table = schema.Table('customers', metadata,
    schema.Column('id', types.Integer, nullable=False,
primary_key=True),
    schema.Column('balance', types.Numeric(precision=20, length=6),
nullable=False, default=0.000000),
)

class Customers(object):
    pass

orm.mapper(Customers, customers_table)
--- End model.py ---

I imagine I can do this the following:

Add this line:
from sqlalchemy.types import Numberic

Modify this line to read:
    schema.Column('balance', Numeric(precision=20, scale=6),
nullable=False, default=0.000000),

Ideally, it would be cleaner if I just added some code at the top and
modified this line to read:
    schema.Column('balance', types.Numeric(precision=20, scale=6),
nullable=False, default=0.000000),

Thanks,
Julian

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to