[sqlalchemy] Re: single Session, queries against multiple classes issues

2006-12-19 Thread Alan Franzoni
Just a small update.

First, my system: Ubuntu Edgy, SQLAlchemy 0.3.3, psycopg 2.0.5, postgres
8.1.4, python2.5.

I've realized this issue is highly strange, it seems related to something I
can't understand.

I'm using a custom metaclass system to map everything from my metadata to
objects. If I add a mapper for the MtM relation after everything has been
built, I find everything works fine.

But the manytoone and manytomany mappings are handled, in my system, by the
metaclass itself. The mapping happens in the metaclass' __init__ method
*after* the super(MetaClass, self).__init__(classname, bases, classdict) has
been called, hence the class has been already constructed normally.

Everything else works fine: manytoone properties are assigned correctly and
they work fine.

I'm now starting a debugging session and I will provide more info ASAP.




-- 
Alan Franzoni [EMAIL PROTECTED]
-
Togli .xyz dalla mia email per contattarmi.
Remove .xyz from my address in order to contact me.
-
GPG Key Fingerprint (Key ID = FE068F3E):
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E


--~--~-~--~~~---~--~~
 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: Misunderstanding something with autoloading

2006-12-19 Thread Sean Davis

On Tuesday 19 December 2006 05:51, Alan Franzoni wrote:
   from sqlalchemy import *
   db = create_engine('postgres://user:[EMAIL PROTECTED]/test5')
   metadata = BoundMetaData(db)
   tb = Table('gffdata',metadata,autoload=True)

 This works fine on my system (ubuntu edgy, x86, python 2.5, postgresql
 8.1.4, psycopg 2.0.5, SA 0.3.3), could you please post the details of
 yours?

Thanks for trying it.  I am on openSUSE 10.2 x86_64, postgres 8.2 (running 
remotely on an Apple XServer), psycopy2.0.5.1, SA 0.3.3.  

I played a bit more and it happens only with a particular database.  When 
connecting to another database, it seems to work just fine.  I'll look into 
it more here, as it seems to be idiosyncratic.  If I come to any hard 
conclusions, I'll forward them along.  

Sean

--~--~-~--~~~---~--~~
 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: Misunderstanding something with autoloading

2006-12-19 Thread Alan Franzoni

 I played a bit more and it happens only with a particular database.  When
 connecting to another database, it seems to work just fine.  I'll look
 into
 it more here, as it seems to be idiosyncratic.  If I come to any hard
 conclusions, I'll forward them along.



By taking a look at the file, I guess this could be a column/arguments
mismatch. In a debug session, put a breakpoint at line 385 in
postgres.pyand take a look at what 'attype' is and at the value of
'args' and 'kwargs'.

Also, please remember that this glitch could be postgresql-related. 8.2 is
very new, and I don't know if either SQLAlchemy or psycopg2 are well-tested
against it. You could try another DB-adapter as well.





-- 
Alan Franzoni [EMAIL PROTECTED]
-
Togli .xyz dalla mia email per contattarmi.
Remove .xyz from my address in order to contact me.
-
GPG Key Fingerprint (Key ID = FE068F3E):
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E


--~--~-~--~~~---~--~~
 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: how to assign values to columns of a mapper?

2006-12-19 Thread Michael Bayer

at this point you need to produce a full example that reproduces your
issue.


--~--~-~--~~~---~--~~
 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: python ORM

2006-12-19 Thread Ilias Lazaridis

Ο/Η Michael Bayer έγραψε:
 django was not available to the public until it was fully functional
 (youd go to the site and just get a coming soon-style splash
 page)..and even then it was already in production use in earlier forms.
  they knew that if you release something that wasnt polished and would
 lead to user frustration, people would get disinterested and leave.
 the strategy seems to have worked for them.

I understand your elaborations.

You should possibly close sqlalchemy, too - until it's fully
functional and does not frustrate users.

Same for turbogears and other open source projects (like django, which
is still not fully functional, mainly due to it's deficient ORM layer).

Or you can keep the development _open_, thus users and other developers
can review the _source_ and contribute ideas, requirements, code etc..

 its not your grandfather's open source community !

Please leave relatives out of the discussions.

.

--
http://case.lazaridis.com/wiki/Persist


--~--~-~--~~~---~--~~
 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] column_prefix()

2006-12-19 Thread Julien Cigar

Hello,

I'm using SQLAlchemy 0.3.1 with Python 2.4 and PostgreSQL
I have a strange problem with property(), it seems that they're not 
propagated to the children classes :

Here is the code which fail :

File A


assign_mapper(session_context, taxonomy.Taxonomy, table_taxonomies,
  polymorphic_on=table_taxonomies.c.rank, column_prefix='_')

assign_mapper(session_context, taxonomy.Family, 
inherits=taxonomy.Taxonomy.mapper,
  polymorphic_identity='family', column_prefix='_')


File B


class Taxonomy(object):

def __init__(self, **kwargs):
name = kwargs.get('name')
if name is not None:
self.name = name

(...)
 
# property for column name

def _set_name(self, value):
value = ' '.join(value.split()).capitalize()
   
if len(value):
self._name = value
else:
raise ValueError('Invalid name')
   
def _get_name(self):
return self._name

name = property(_get_name, _set_name)
   
(...)

class Family(Taxonomy):
   
def __init__(self, **kwargs):
super(Family, self).__init__(**kwargs)

(...)

  from application.models.taxonomy import Family
  Family.selectone(Family.c.name=='Aaa heherez')
Traceback (most recent call last):
  File stdin, line 1, in ?
  File /usr/lib/python2.4/site-packages/sqlalchemy/util.py, line 115, 
in __getattr__
raise AttributeError(key)
AttributeError: name
 

Is this normal or I missed something ?

In advance thanks,

Julien

-- 
Julien Cigar
Belgian Biodiversity Platform
http://www.biodiversity.be
Université Libre de Bruxelles
Campus de la Plaine CP 257
Bâtiment NO, Bureau 4 N4 115C (Niveau 4)
Boulevard du Triomphe, entrée ULB 2
B-1050 Bruxelles
office: [EMAIL PROTECTED]


--~--~-~--~~~---~--~~
 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: Misunderstanding something with autoloading

2006-12-19 Thread Michael Bayer

this is a typing error; your PG database is giving richer information
for a particular type than the selected SQLAlchemy TypeEngine class
expects to receive.  as far as what that type is and what the richer
information is, youd either have to put some debug print statements on
line 385 of postgres.py or at least show us the table youre trying to
reflect.


--~--~-~--~~~---~--~~
 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: python ORM

2006-12-19 Thread Michael Bayer

after that post, ill never again doubt your trollish reputation.


--~--~-~--~~~---~--~~
 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: single Session, queries against multiple classes issues

2006-12-19 Thread Michael Bayer

im sure if you put a session.clear() in between those two statements
then they both would independently work.  since the instances() step of
a query does not re-instantiate or re-populate instances that are
already present in the session, there is probably some difference in
loading that is masking the results for the other one.


--~--~-~--~~~---~--~~
 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: column_prefix()

2006-12-19 Thread Michael Bayer

yeah the prop on your c instance is going to be called _name in
this case.  use the synonym() function to put name back on your
mapper as a property.

http://www.sqlalchemy.org/docs/adv_datamapping.myt#advdatamapping_properties_overriding


--~--~-~--~~~---~--~~
 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: python ORM

2006-12-19 Thread Michael Bayer

closing off posting for this thread.


--~--~-~--~~~---~--~~
 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] Cascade delete-orphan: child deleted althought still referenced ?

2006-12-19 Thread Nebur

I create a child table and a parent table. The latter holds a relation
to the child with delete-orphan cascade.
When I delete _the first_ of my 2 parents, the child is immediately
deleted, too.
***
This is my first attempt to use delete-orphan. I don't dare to report
it as a bug,
for the case I misunderstand the SA API.

The complete code:


from sqlalchemy import *

class Child(object):
def __init__(self, name):
self.childname = name
class Parent(object):
def __init__(self, name):
self.parentname = name

db = create_engine(mysql://[EMAIL PROTECTED]/test_cascade)
db.echo = True
session = create_session()

metadata = BoundMetaData(db)
t_parent = Table(parent,metadata,
Column(id,Integer,primary_key=True),
Column(parentname,String()),
Column(child_id,Integer,ForeignKey(child.id)),
mysql_engine=InnoDB,
)
t_child = Table(child,metadata,
Column(id,Integer,primary_key=True),
Column(childname,String()),
mysql_engine=InnoDB,
)
metadata.create_all()
mapper(Child, t_child)
mapper(Parent, t_parent, properties={
mychild:relation(Child,cascade=delete-orphan),
})

# create a child + 2 parents:
aChild = Child(aChild);session.save(aChild)
aParent1 = Parent(aParent1); aParent1.mychild=aChild;
session.save(aParent1)
aParent2 = Parent(aParent2); aParent2.mychild=aChild;
session.save(aParent2)
session.flush()

# it doesn't matter whether I create a new session here, or continue
with the old one

# delete first parent:
session.delete(aParent1)

# With InnoDB, the next flush raises Foreign Key constraint failure
# because aChild is deleted - while aParent2 ist still referencing it !
session.flush() #fails

# with MyISAM, I can still go ahead ...
print session.query(Child).get_by(childname=aChild) # the child is
deleted
# ... and try to delete second parent:
session.delete(aParent2) #
# next flush raises an error because aChild is not attached to session
anymore
session.flush()

It this a Bug, or did I misuse the ORM... ?
Regards
 Ruben

-
Versions: sqlalchemy 0.3.3 and 0.3.1 and MySQL5.


--~--~-~--~~~---~--~~
 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: Cascade delete-orphan: child deleted althought still referenced ?

2006-12-19 Thread Michael Bayer

the orphan detection only supports one parent at a 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: single Session, queries against multiple classes issues

2006-12-19 Thread Alan Franzoni
Yes, you're right, even tough this doesn't help (I need all objects to be in
the same session) and I think I've just found out what raises the problem.

The problem is my MapperExtension. I wanted to call __init__ on my instances
in order to initialize some meta-properties which work on a per-instance
basis; this behaviour seems to interfere with instance loading at some
point.

I'm writing a test case to let you see the problem; in the meantime,  have
converted what stayed in my __init__ to be done in __new__.

-- 
Alan Franzoni [EMAIL PROTECTED]
-
Togli .xyz dalla mia email per contattarmi.
Remove .xyz from my address in order to contact me.
-
GPG Key Fingerprint (Key ID = FE068F3E):
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E


--~--~-~--~~~---~--~~
 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] MapperExtension calling __init__ and many-to-many relations problem

2006-12-19 Thread Alan Franzoni
Hello,
I'm attaching the test case for this issue. The test case includes some ifs
to prevent too many objects to be created and/or to help testing.

Unmodified, this will output:

[] 0
[] 0
[] 0


just changing the CustomMapperExtension if to False (effectively deleting
the create_instance override) restores full software functionality. I
couldn't understand what's the problem - just to let you know, my software
worked 100% until i reached this many-to-many relations part - manytoone and
onetomany work fine.


-- 
Alan Franzoni [EMAIL PROTECTED]
-
Togli .xyz dalla mia email per contattarmi.
Remove .xyz from my address in order to contact me.
-
GPG Key Fingerprint (Key ID = FE068F3E):
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E


--~--~-~--~~~---~--~~
 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
-~--~~~~--~~--~--~---
from sqlalchemy import *
import random
import string
import sys
import logging

random.seed()

#quick random string recipe by Pradeep Kishore Gowda found on ASPN
def nicepass(alpha=6,numeric=2):

returns a human-readble password (say rol86din instead of 
a difficult to remember K8Yn9muL ) 

vowels = ['a','e','i','o','u']
consonants = [a for a in string.ascii_lowercase if a not in vowels]
digits = string.digits

utility functions
def a_part(slen):
ret = ''
for i in range(slen):
if i%2 ==0:
randid = random.randint(0,20) #number of consonants
ret += consonants[randid]
else:
randid = random.randint(0,4) #number of vowels
ret += vowels[randid]
return ret

def n_part(slen):
ret = ''
for i in range(slen):
randid = random.randint(0,9) #number of digits
ret += digits[randid]
return ret

 
fpl = alpha/2
if alpha % 2 :
fpl = int(alpha/2) + 1 
lpl = alpha - fpl

start = a_part(fpl)
mid = n_part(numeric)
end = a_part(lpl)

return %s%s%s % (start,mid,end)

postgres_engine = create_engine(postgres://user:[EMAIL PROTECTED]:5432/testsa, echo=False, encoding=utf8, convert_unicode=True)
metadata = BoundMetaData(postgres_engine)

editore = Table(editore, metadata,
Column(id, Integer, Sequence(editore_id_seq),
primary_key=True ),
Column(editore, String(40), nullable=False, unique=True),
Column(edit_indirizzo, String(60)),
Column(edit_telefono, String(30)),
Column(edit_sito, String(80)),
Column(edit_email, String(50)),
Column(edit_note, TEXT),
Column(last_upd, DateTime)
   )
   
reparto = Table(reparto, metadata,
Column(id, Integer, Sequence(reparto_id_seq),
primary_key=True),
Column(reparto, String(15), nullable=False, unique=True),
Column(rep_descrizione, String(60) ),
Column(aliq, Integer ),
Column(last_upd, DateTime)
)


editorereparto = Table(editorereparto, metadata,
Column(editore_id, Integer, ForeignKey(editore.id), primary_key=True),
Column(reparto_id, Integer, ForeignKey(reparto.id), primary_key=True),
Column(last_upd, DateTime),
)

formato = Table(formato, metadata,
Column(id, Integer, Sequence(formato_id_seq),
primary_key=True, nullable=False, ),
Column(formato, String(20),  nullable=False, unique=True),
Column(form_descr, String(60)),
Column(last_upd, DateTime),
)
 

formatoreparto = Table(formatoreparto, metadata,
Column(reparto_id, Integer, ForeignKey(reparto.id), primary_key=True),
Column(formato_id, Integer, ForeignKey(formato.id),primary_key=True ),
Column(last_upd, DateTime),
   
)


metadata.create_all()

class Reparto(object):
pass

class Editore(object):
pass

class Formato(object):
pass

class CustomMapperExtension(MapperExtension):

#choose whether to override default create_instance
if True:
def create_instance(self, mapper, selectcontext, row, class_):
   return class_()

   
CustomExt=CustomMapperExtension()

Reparto.mapper = mapper(Reparto, reparto, extension=CustomExt)
Editore.mapper = mapper(Editore, editore, extension=CustomExt)
Formato.mapper = mapper(Formato, formato, extension=CustomExt)


#mtm properties block - without backref
if True:
Reparto.mapper.add_property(editori, relation(Editore, secondary=editorereparto,
lazy=True, cascade=all))
#))

[sqlalchemy] Re: SQLAlchemy and py2exe problem

2006-12-19 Thread ml

Hi!

I had similar problem with module postgres. py2exe didn't automaticaly
include the module so I simply put import
sqlalchemy.databases.postgres into the main script. Perhaps you should
try something like this with the logging.

DS


Karlo Lozovina píše v Út 19. 12. 2006 v 04:01 +:
 Hi all,
 
 I've posted this few minutes ago on c.l.python, but since I'm
 desperate, I'll do it here to:
 
 I'm working with SQLAlchemy 0.3.3, Python 2.5 and py2exe 0.6.5. This
 simple scripts fails when I run test.exe:
 
 *** test.py: ***
 import sqlalchemy
 print 'Test'
 ***
 
 It works when interpreted by Python, but when running it from compiled
 py2exe binary, it fails with this error:
 
 Traceback (most recent call last):
   File main.py, line 1, in module
   File sqlalchemy\__init__.pyc, line 10, in module
   File sqlalchemy\orm\__init__.pyc, line 12, in module
   File sqlalchemy\orm\mapper.pyc, line 7, in module
   File sqlalchemy\logging.pyc, line 30, in module
 ImportError: No module named logging
 
 Ofcourse, library.zip (in the dist directory) contains 'sqlalchemy
 \logging.pyc'. After I copy logging.pyc to library.zips' root, I get
 this error:
 
 Traceback (most recent call last):
   File main.py, line 1, in module
   File sqlalchemy\__init__.pyc, line 10, in module
   File sqlalchemy\orm\__init__.pyc, line 12, in module
   File sqlalchemy\orm\mapper.pyc, line 7, in module
   File sqlalchemy\logging.pyc, line 30, in module
   File sqlalchemy\logging.pyc, line 33, in module
 AttributeError: 'module' object has no attribute 'getLogger'
 
 I really don't know what to do next, so any kind of help is
 appreciated. First of all, I'm wondering is this SQLAlchemys' problem,
 or is py2exe guilty?
 
 Thanks guys...
 
 
  


--~--~-~--~~~---~--~~
 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: MapperExtension calling __init__ and many-to-many relations problem

2006-12-19 Thread Michael Bayer

its a bug, its fixed in r2171.

also i can safely say that apparently, almost nobody uses
create_instance(), since this bug appears very easily with any kind of
lazy or deferred loaders associated with the class.


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