[sqlalchemy] Re: problem with server_default (and/or sa.PassiveDefault in 0.5.beta1

2008-07-13 Thread Kless

It fails with fields of date. It shows:

created_at=*datetime.datetime(2008, 7, 13, 13, 59, 57)*

On Jun 21, 7:25 pm, Michael Bayer [EMAIL PROTECTED] wrote:
 that __repr__ is pretty tortured too; a typical ORM-agnostic approach  
 is:

      def __repr__(self):
              return %s(%s) % (
                  (self.__class__.__name__),
                  ', '.join([%s=%r % (key, getattr(self, key))
                             for key in sorted(self.__dict__.keys())
                             if not key.startswith('_')]))
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: problem with server_default (and/or sa.PassiveDefault in 0.5.beta1

2008-06-23 Thread Werner F. Bruhin

Svilen and Michael,

Thanks for all the pointers.  Will look into this all and read up some 
more on declarative (I like its approach, having things together) and do 
some more test scripts for my application.

Werner

Michael Bayer wrote:
 that __repr__ is pretty tortured too; a typical ORM-agnostic approach  
 is:

  def __repr__(self):
  return %s(%s) % (
  (self.__class__.__name__),
  ', '.join([%s=%r % (key, getattr(self, key))
 for key in sorted(self.__dict__.keys())
 if not key.startswith('_')]))



 


   


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



[sqlalchemy] Re: problem with server_default (and/or sa.PassiveDefault in 0.5.beta1

2008-06-21 Thread az

u want to autoassign a value to each column at __init__ or what?

u could have some Base2 that does the repr/init/whatever as mixin.

say have a property _my_attrs that could walk once the 
class.__dict__  - if u want only local stuff - or dir(self) - if u 
want all inherited stuff too - , and looking for 
isinstance(x,sa.Column); or walk 
class_mapper(self.__class__).properties (or whatever the current name 
of it) - if u want mapped things only. Then u can cache the resulting 
list, and reuse it later. u can do it in a metaclass (not the for 
mapper' way though).
beware, automatic setting or repr's can easy fall into recursion - 
just give an A pointing to B pointing to same A.

everybody needs something like this but then everyone wants it his own 
way so whatever u do.
see one in  
http://dbcook.svn.sourceforge.net/viewvc/dbcook/static_type/util/str.py?revision=178view=markup
another in 
http://dbcook.svn.sourceforge.net/viewvc/dbcook/trunk/dbcook/baseobj.py?revision=224view=markup

as of the declarative ... and typing five times same name... 
there's also elixir and dbcook.
first one is heavily used and well known. 
the other one is by me, and goes long way further in hiding the DB 
where it is not needed to be seen, but noone else is using it so far.
YMMV

On Saturday 21 June 2008 18:38:05 Werner F. Bruhin wrote:
 The debug problem (see traceback below) I had is due to the code I
 used from the wiki:
 http://www.sqlalchemy.org/trac/wiki/UsageRecipes/GenericOrmBaseClas
s

 The code does not work in 0.5 anymore, one reason is that the
 MyClass.c attribute is no longer there.

 I looked at the declarative stuff and I am thinking of switching
 over to it, but it still has the problem that each column name
 has to be typed five times (including the init and repr method
 stuff).  O.K. this is only in the model, done once but still it
 opens things up for errors.

 Looking at
 http://www.sqlalchemy.org/docs/05/ormtutorial.html#datamapping_dec
larative it would be really nice if the init and repr methods
 are automagically generated, or maybe something like a mixin could
 be provided.

 In my test I added the following to MyClass and it works.  But I am
 sure this is not the most elegant way of doing this and I am not
 sure how one changes this to a mixin without stuffing other things
 up.

 Would appreciate if anyone can push me in the right direction.
 Werner

 class Prefminimal(Base):
 __tablename__ = 'preferences'

 prefid = sa.Column(sa.Integer,
 sa.Sequence('gen_preferences_prefid'), primary_key=True,
 nullable=False) dbstructure = sa.Column(sa.Integer)
 dbdata = sa.Column(sa.Integer)

 # added stuff
 myColumns = []
 for att in dir():
 if not att.startswith(('_', 'myColumns')):
 myColumns.append(att)

 def __repr__(self):
 atts = []
 for att in self.myColumns:
 atts.append( (att, getattr(self, att)))

 return self.__class__.__name__ + '(' + ', '.join(x[0] + '='
 + repr(x[1]) for x in atts) + ')'

 Werner F. Bruhin wrote:
  Traceback (most recent call last):
File
  C:\Python25\Lib\site-packages\boa\Debugger\IsolatedDebugger.py,
  line 823, in run
  Bdb.run(self, cmd, globals, locals)
File C:\Python25\lib\bdb.py, line 366, in run
  exec cmd in globals, locals
File string, line 1, in module
File C:\Dev\twcb\Program\twcb.py, line 1108, in module
  main()
File C:\Dev\twcb\Program\twcb.py, line 1104, in main
  appl = BoaApp()
File
  C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py,
  line 7912, in __init__
  self._BootstrapApp()
File
  C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py,
  line 7487, in _BootstrapApp
  return _core_.PyApp__BootstrapApp(*args, **kwargs)
File C:\Dev\twcb\Program\twcb.py, line 266, in OnInit
  self.prefs = self.ds.query(db.prefminimal).get(1)
File
  c:\python25\lib\site-packages\sqlalchemy-0.5.0beta1-py2.5.egg\sq
 lalchemy\orm\session.py, line 894, in query
  return self._query_cls(entities, self, **kwargs)
File
  c:\python25\lib\site-packages\sqlalchemy-0.5.0beta1-py2.5.egg\sq
 lalchemy\orm\query.py, line 97, in __init__
  self.__setup_aliasizers(self._entities)
File
  c:\python25\lib\site-packages\sqlalchemy-0.5.0beta1-py2.5.egg\sq
 lalchemy\orm\query.py, line 111, in __setup_aliasizers
  mapper, selectable, is_aliased_class = _entity_info(entity,
  ent.entity_name)
File
  c:\python25\lib\site-packages\sqlalchemy-0.5.0beta1-py2.5.egg\sq
 lalchemy\orm\util.py, line 401, in _entity_info
  mapper = entity.compile()
File
  c:\python25\lib\site-packages\sqlalchemy-0.5.0beta1-py2.5.egg\sq
 lalchemy\orm\mapper.py, line 370, in compile
  mapper.__initialize_properties()
File
  c:\python25\lib\site-packages\sqlalchemy-0.5.0beta1-py2.5.egg\sq
 lalchemy\orm\mapper.py, line 391, in __initialize_properties
  prop.init(key, self)
File
  

[sqlalchemy] Re: problem with server_default (and/or sa.PassiveDefault in 0.5.beta1

2008-06-21 Thread az

sorry, here one for the init part: set_as_attributes() in
http://dbcook.svn.sourceforge.net/viewvc/dbcook/trunk/tests/util/struct.py?revision=6view=markup
or much simpler, setattr_kargs() in
http://dbcook.svn.sourceforge.net/viewvc/dbcook/trunk/dbcook/util/attr.py?revision=288view=markup

On Saturday 21 June 2008 18:38:05 Werner F. Bruhin wrote:
 I looked at the declarative stuff and I am thinking of switching
 over to it, but it still has the problem that each column name
 has to be typed five times (including the init and repr method
 stuff).  O.K. this is only in the model, done once but still it
 opens things up for errors.


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



[sqlalchemy] Re: problem with server_default (and/or sa.PassiveDefault in 0.5.beta1

2008-06-21 Thread Michael Bayer

that __repr__ is pretty tortured too; a typical ORM-agnostic approach  
is:

 def __repr__(self):
 return %s(%s) % (
 (self.__class__.__name__),
 ', '.join([%s=%r % (key, getattr(self, key))
for key in sorted(self.__dict__.keys())
if not key.startswith('_')]))



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



[sqlalchemy] Re: problem with server_default (and/or sa.PassiveDefault in 0.5.beta1

2008-06-18 Thread Werner F. Bruhin

I did some more research on this.

If I change back to 0.4.3, i.e. change my model to use:
##pkg_resources.require(sqlalchemy) # get latest version
pkg_resources.require(sqlalchemy==0.4.3) # use a specific version

Then I can debug my code, i.e. my application starts.

So, I changed it back to 0.5.beta1 and tried to find out were the 
problem starts in my code, it is on the following line.

self.prefs = self.ds.query(db.prefminimal).get(1)

prefminimal is a redefinition of the preferences table, i.e. it 
only maps columns which are present in the preferences table regardless 
of the version of my application.

The model for it is:
metadataMin = sa.MetaData()
prefminimal_table = sa.Table(u'preferences', metadataMin,
sa.Column(u'prefid', sa.Integer(), 
sa.Sequence('gen_preferences_prefid'), primary_key=True, nullable=False),
sa.Column(u'fk_langid', sa.Integer(), 
sa.ForeignKey(u'language.langid'), nullable=False),
sa.Column(u'dbstructure', sa.Integer()),
sa.Column(u'dbdata', sa.Integer()),
)


class Prefminimal(OrmObject):
pass


prefminimal = sao.mapper(Prefminimal, prefminimal_table,
properties={
})

All other tables (including the full version of preferences) are using 
metadata = sa.MetaData(), instead of the metadataMin I use for the 
prefminimal definition.

I got this working some month ago, but maybe this is not the right way 
to go about it and it bits me now?

Werner



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



[sqlalchemy] Re: problem with server_default (and/or sa.PassiveDefault in 0.5.beta1

2008-06-18 Thread Werner F. Bruhin

Werner F. Bruhin wrote:
 I did some more research on this.

 If I change back to 0.4.3, i.e. change my model to use:
 ##pkg_resources.require(sqlalchemy) # get latest version
 pkg_resources.require(sqlalchemy==0.4.3) # use a specific version

 Then I can debug my code, i.e. my application starts.

 So, I changed it back to 0.5.beta1 and tried to find out were the 
 problem starts in my code, it is on the following line.

 self.prefs = self.ds.query(db.prefminimal).get(1)
   
I think it has nothing to do with the prefminimal, it happens on 
whatever is the first query on whatever table.

I just run a small test script with the idle debugger and I see the same 
exception.

If I run it in Idle with the debugger but use SA 0.4.3 then it runs o.k.

I hope this info helps.

Werner

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



[sqlalchemy] Re: problem with server_default (and/or sa.PassiveDefault in 0.5.beta1

2008-06-18 Thread Michael Bayer


On Jun 18, 2008, at 4:05 AM, Werner F. Bruhin wrote:

 All other tables (including the full version of preferences) are using
 metadata = sa.MetaData(), instead of the metadataMin I use for the
 prefminimal definition.

 I got this working some month ago, but maybe this is not the right way
 to go about it and it bits me now?


using two separate MetaData objects, if I correctly understand that's  
what you're doing, is not going to work at all if that Table has any  
ForeignKey objects (which it does).   I dont see the use case for two  
distinct MDs.

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



[sqlalchemy] Re: problem with server_default (and/or sa.PassiveDefault in 0.5.beta1

2008-06-18 Thread Werner F. Bruhin

Michael Bayer wrote:
 On Jun 18, 2008, at 4:05 AM, Werner F. Bruhin wrote:

   
 All other tables (including the full version of preferences) are using
 metadata = sa.MetaData(), instead of the metadataMin I use for the
 prefminimal definition.

 I got this working some month ago, but maybe this is not the right way
 to go about it and it bits me now?

 

 using two separate MetaData objects, if I correctly understand that's  
 what you're doing, is not going to work at all if that Table has any  
 ForeignKey objects (which it does).   I dont see the use case for two  
 distinct MDs.
   
What I need to do at start up of the application is to check a couple of 
columns in table preferences to check what version the database is, 
then if it is an older version I do the upgrade of the database 
(metadata etc) and update the columns in the table.

I can not read all the columns of the table as there might be columns 
defined for this new release which are not present until the upgrade is 
finished.

Would something like this work for me session.query(Preferences.col1, 
Preferences.col2) and have columns defined in the model which are not 
yet present in the database?

If the query approach does not work what alternatives would I have?

Werner


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



[sqlalchemy] Re: problem with server_default (and/or sa.PassiveDefault in 0.5.beta1

2008-06-18 Thread az

On Wednesday 18 June 2008 17:21:00 Werner F. Bruhin wrote:
 Michael Bayer wrote:
  On Jun 18, 2008, at 4:05 AM, Werner F. Bruhin wrote:
  All other tables (including the full version of preferences) are
  using metadata = sa.MetaData(), instead of the metadataMin I
  use for the prefminimal definition.
 
  I got this working some month ago, but maybe this is not the
  right way to go about it and it bits me now?
 
  using two separate MetaData objects, if I correctly understand
  that's what you're doing, is not going to work at all if that
  Table has any ForeignKey objects (which it does).   I dont see
  the use case for two distinct MDs.

 What I need to do at start up of the application is to check a
 couple of columns in table preferences to check what version the
 database is, then if it is an older version I do the upgrade of the
 database (metadata etc) and update the columns in the table.

 I can not read all the columns of the table as there might be
 columns defined for this new release which are not present until
 the upgrade is finished.

 Would something like this work for me
 session.query(Preferences.col1, Preferences.col2) and have
 columns defined in the model which are not yet present in the
 database?

 If the query approach does not work what alternatives would I have?


cant u drop the Min-version once u finished using it? thus having only 
one metadata to same engine at same time.

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



[sqlalchemy] Re: problem with server_default (and/or sa.PassiveDefault in 0.5.beta1

2008-06-17 Thread Werner F. Bruhin

Michael,

Michael Bayer wrote:

 On Jun 17, 1:06 pm, Werner F. Bruhin [EMAIL PROTECTED] wrote:
   
 I just got beta1 and I run into a problem with the following:

 sa.Column(u'consumedvalue', sa.Numeric(precision=18, length=2,
 asdecimal=True), sa.PassiveDefault()),

 consumedvalue is a readonly column (i.e. computed by Firebird SQL) and I
 am getting the following exception when I try to debug (in Boa), the
 same happens if I change the above to use server_default=.

 Do I need to change something else in the model.  For each of these type
 of columns I also have the following:

 class Consumption(object):
 def consumedvalue(self):
 return self._consumedvalue
 consumedvalue = property(consumedvalue)
 

 the mapper will automatically map the consumedvalue column to the
 consumedvalue attribute on the class.  The descriptor you've placed
 there conflicts with it.  You need to tell the mapper about the
 _consumedvalue name you're using, which is illustrated here:
 http://www.sqlalchemy.org/docs/05/mappers.html#advdatamapping_mapper_overriding
   
I already have this (see below), sorry forgot to mention this before.  
Note that my model worked under 0.4.3 and it does in 0.5beta1, i.e. I 
can insert a record into Consumption.  I only get the exception shown in 
the previous email when I try to run it through the debugger (to check 
something unrelated to SA).

Werner

consumption = sao.mapper(Consumption, consumption_table,
properties={
'reason_ls': sao.relation(Reason_Ls),
'rating': sao.relation(Rating),
'cbbottle': sao.relation(Cbbottle),
'cellar': sao.relation(Cellar),
'_consumedvalue': consumption_table.c.consumedvalue,
'consumedvalue': sao.synonym('_consumedvalue'),
})


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