[sqlalchemy] Re: PostgreSQL - fetching boolean type gives integer type

2006-12-22 Thread Alan Franzoni



in sanjay's example, its inserting an integer 1 or 0 value, not True.



I think that's the problem. He's saying:

What happens is, while fetching, boolean columns are fetched as integer
type (0, 1).

He's trying to set the show_ads column from the value of another column
(directly pulled from the db)

So, I suppose a) the columns are boolean, and b) the values were inserted as
booleans, otherwise they couldn't have been inserted at all (at least I
suppose so; if psycopg complains once, it should always complain about that
type-mismatch). Hence the problem is that the value is returned as integer,
but needs a boolean to be re-inserted.

In my example, I just showed that bool values in my own system *are*
returned as bool.

It'd be nice now to know from Sanjay which system  version is using.

--
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: PostgreSQL - fetching boolean type gives integer type

2006-12-22 Thread Alan Franzoni


My system was having PostgreSQL 8.1.4 and psycopg. After Alan's code
failing in my system, I doubted on psycopg. With some struggle, I
successfully installed psycopg2 and removed psycopg, and things worked!



You'll find really comfortable with psycopg2. I, too, used psycopg1 till
August 2006 or so; then I found out it was dealing very strangely with
unicode data.

I lurk on the psycopg ML as well, and Fog (psycopg1  2 creator) once said
that he's not got enough time to handle both psycopg1 maintenance  psycopg2
development, hence he'll fix only highly critical bugs on the 1.x release;
any active development is done on release 2.x only right now.


--
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] SessionTransaction behaviour

2006-12-22 Thread Alan Franzoni

Hello, I'm experiencing what I think is an unexpected behaviour using
SessionTransaction in SA 0.3.3. The following example is a slightly modified
one from SA's SessionTransaction docs.

#begin sa_example.py
sess = create_session()
trans = sess.create_transaction()

item1 = sess.query(Reparto).get_by(id=1)
item2 = sess.query(Reparto).get_by(id=2)
item1.rep_descrizione=uone
item2.rep_descrizione=utwo

trans.rollback()
trans.close()

print list(sess)
sess.flush()

sess.clear()
sess.close()
sess = create_session()
item1 = sess.query(Reparto).get_by(id=1)
item2 = sess.query(Reparto).get_by(id=2)

print item1.rep_descrizione, item2.rep_descrizione
#end sa_example.py

I don't know if it's a common doubt or if it's just me that didn't
understand something about uow/session behaviour, but I would expect that
objects taken into the query during the transaction to be expunged when
rolling back the transaction, or at least to be taken back to the values
they had when they where pulled from the DB.

Of course I can do around this using an 'external' db transaction:

#begin sa_example.py
conn = engine.connect()
dbtrans = conn.begin()
sess = create_session(bind_to=conn)
#trans = sess.create_transaction()

item1 = sess.query(Reparto).get_by(id=1)
item2 = sess.query(Reparto).get_by(id=2)
item1.rep_descrizione=ufive
item2.rep_descrizione=usix

sess.flush()
dbtrans.rollback()

sess.clear()
sess.close()
sess = create_session()
item1 = sess.query(Reparto).get_by(id=1)
item2 = sess.query(Reparto).get_by(id=2)

print item1.rep_descrizione, item2.rep_descrizione
#end sa_example.py

But then I don't understand what SessionTransaction is there for?

--
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: SqlSoup error

2006-12-22 Thread Alan Franzoni


Any suggestions on what I am missing?



I don't use sqlsoup and I don't know whether you not using it correctly;
btw, if you're in hurry, as a simple workaround, I suggest you add this line
to sqlsoup.py, line 369, just above klass_query =... :

klass._mapper.compile()


and see if it works.


--
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: PostgreSQL - fetching boolean type gives integer type

2006-12-21 Thread Alan Franzoni

Remember this is not a wiki! {{{}}} won't format the code as you might
expect.

BTW, everything ok here on pgsql; boolean are True or False. You should try
posting at least your db metadata and tell us which version of pgsql and
psycopg you're using.

--
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: problem with backref

2006-12-21 Thread Alan Franzoni



A better solution is to do
sess = object_session(self)



That's wonderful and I didn't know about it!

Finally I'll give up passing session around my code!

Thanks!

--
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: PostgreSQL - fetching boolean type gives integer type

2006-12-21 Thread Alan Franzoni



thats  true the PG boolean type is not currently performing any
translation on the value, meaning the 0 and 1 is what psycopg2 is
giving you.  however, the value should be able to go right back in if
thats what its giving you, else psycopg2 is not consistent with itself.



? which version of pgsql and/or psycopg2 are both of you employing? is a
pgsql 8.2-related issue?

from sqlalchemy import *

postgres_engine = create_engine(postgres://user:[EMAIL PROTECTED]:5432/testsa
)
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(prova, Boolean),
  )

metadata.create_all()

editore.insert().execute(id=3, editore=agboh, prova=True)

e = editore.select(editore.c.id==2).execute().fetchone()

print e.prova, type(e.prova)


Result:
True type 'bool'

--
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: problem with backref

2006-12-20 Thread Alan Franzoni

[italian mode]
Come va Manlio? Ci sente anche qui alla fine :-) io per la fine dell'anno
dovrei riuscire a finire il progetto su cui sto lavorando e potrĂ² riprendere
finalmente il mio lavoro anche con python.it!
[/italian mode]

1st:
In order to use a transaction with a pre-existent connection, you should
bind the session to the connection. This can be done by creating the session
this way:

sess = create_session(bind_to=conn)

This is useful if you want to work both with the SQL layer and with the ORM
layer of SA. If you just want to use the ORM layer (like you appear to do),
forget the 'conn' and 'trans' in your code, and just do

sess = create_session()
trans = sess.create_transaction()

and just use trans.rollback() or trans.commit() in your code.

2nd:
If I got what you want: you want to be able to remove the 'B' instance from
the 'A' instance without removing the 'A' object from the db, right?
session.delete() is the way to go, because that's the way you remove objects
using the SA ORM. And you must pull out the 'cascade='all'' from the 'a'
relation, because if you instruct SA to do this, it will try to remove its
related object (the 'A' instance), which is not what you wont.

Look at this and tell me if it produces the result you would expect:

mapper(A, a)
mapper(
   B, b,
   properties={
   'a': relation(
   A, backref=backref('b', lazy=False, uselist=False,
  cascade='all'),
   uselist=False  )
   }
   )



sess = create_session()
o = A('1', '2')
o.b = B(o.x, o.y, '3')

sess.save(o)
sess.flush()
sess.expunge(o)
sess.clear()
del o

o = sess.query(A).get_by(x=1, y=2)
print o.b.z
sess.delete(o.b)
sess.flush()
sess.close()

print o.b
s = a.select()
print s.execute().fetchall()



--
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: problem with backref

2006-12-20 Thread Alan Franzoni



The problem is that it requires the explicit use of the session.
In my case this means that I can not delete the object inside a method
of my class.

class A(object):
def enableB(enable=True):
   if enable:
  self.b = B(...)
   else:
  del self.b


Not a big problem, however.



There's the 'threadlocal' that should let you work as you like, but I've
read its use is discouraged because it could lead to strange bugs.

BTW, couldn't you just pass your session to the methods requiring it?

class A(object):
   def enableB(enable=True, session):
  if enable:
 self.b = B(...)
  else:
 session.delete(self.b)




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

2006-12-18 Thread Alan Franzoni
Hello,
I have encountered a strange behaviour within SA, but since I seem to be
making silly questions lately, I'm not attaching a full test case - I will
if a bug is suspected.


session = create_session()

#1st block
form = session.query(Formato).get_by(id=7).reparti
print form

#2nd block
ed = session.query(Editore).get_by(id=1).reparti
print ed


reparti is a property returning the list of object for a many-to-many
relationship. there're three tables ( reparti, editori, formati ) and two
association tables ( editori_reparti, formati_reparti ); they're both eager;
the three tables have their corresponding classes mapped.

Now, the matter. If I try commenting out either the first or second block, I
get the correct results. But if I run the code as written above, the second
query (this happens even switching their order) returns an empty list.

I have enabled the echo, and both queries seem to get actually executed, and
they look the same when commenting out the code and when having all the code
run.


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

2006-12-16 Thread Alan Franzoni

 SQLAlchemy lets you define separately DB code and python classes, but
 then you hve a real duplication.


Duplication is bad, but you're never forced to duplicate
anything.Pythonoffers all the tools you need to prevent duplication,
and SA offers whatever
you need to 'extract' metadata from tables in order to employ it. Take a
look at what ActiveMapper does.

I'll give you the example implementation of my system: I have defined my own
database through sqlalchemy.

Then I write the 'base' DB class for my system (which may vary depending on
the software I'm working on) and I use a custom metaclass I've created to
sort out all the object-related issues.

In the end, I get a full-working set of mapped classes without ever
duplicating a single line of code, unless I want to override a default
behaviour.

Of course, since SQLAlchemy can't know what are you doing if you use
'strange' naming (well, I guess this could be sorted out anyway by
harvesting globals(), but it's a slow approach), you'll have to trade naming
convention for 'singleness' - e.g., if have a table called 'place', its
corresponding object will be named 'Place'. And if, in another class, I have
a FK column called 'place_id' it will point (for sure!) at the
place.idcolumn, and that class will have a 'place' property.

Try it out, you'll find amazing how easy it's to write such code.

-- 
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: Proposal: session identity_map no longer weak referencing

2006-12-09 Thread Alan Franzoni

  when SA was first released, someone immediately suggested that the
  identity map of Session be weak referencing, which appeared to be an
  obvious improvement, so that you could load as many objects as you want
  from the session and whatever you didnt use would just go away.  but
  now it appears that the more intuitive operation for a Session is that
  things that get loaded into it, stay there, until you say otherwise.


If I got what yoy mean, I think I had suggested something like that
myself... but it was back in SA 0.1 days, when there was no explicit
Session.

But are you saying that doing sth like

a = MappedObject()

session.save(a)

del a


would prevent 'a' from being saved when flushing the session? In SA 0.3.1 it
seems to stay in it. Or it's just a matter of changed attributes, something
like

a = query.get_by(id=x)
a.attribute = 4
del a


?

In both cases, I think the strongly referenced behaviour is OK. If it's in a
session, I want an object to be tracked whatsoever, unless I explicitly
remove it.

-- 
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: ORM and metaclasses init problem

2006-12-09 Thread Alan Franzoni
Sorry, I had checked the docs but not the FAQ. I opened a ticket as well,
feel free to close it. I think it should be stated in a more clear in way in
the docs, though, since it's an unpredictable behaviour.

But was that behaviour present in 0.1.x? I feel a bit estranged about never
noticing that.

Anyway, I don't see what's the possible drawback of calling the original
__init__ . As long as no explicit construction parametr or keyword is
required (which was a requirement back in 0.1.x, I think), it shouldn't
create any problem, and should be more adherent to sqlalchemy's philosophy
of 'not forcing any kind of programming style'.

Thank you anyway!

-- 
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: Changing/Extending mapped objects' properties

2006-10-30 Thread Alan Franzoni
all of these approaches i think are easier than making a subclassedMapper.
Yes, they are indeed. I'll pick either of them. I could also add another mapper flag to be used in conjunction with
column_prefix called query_prefix that just allows the _ to bestripped during get_by/select_by operations, like the extension woulddo.If my requirements are met by an extension, that will surely suffice. I've seen the mapper extensions has a complex constructor already, no need to add an additional keyword argument for such a 'niche' task as mine is.
I dont understand why the Mapper needs to know about theseattributes, if they are not related to database columns or other
database-mapped relationships.I think that it came from a misunderstanding of mine; I probably haven't grasped yet all of sqlalchemy's internals.I thought it was the mapper who mapped the UOWProperty to the class columns, but after debugging for a while I'm not so sure about that. My problems also arise from the fact that it doesn't seem there's any UOWProperty attached to the class till the first instance of the class is created (or pulled from the db), so I might just have looked into the wrong code.
My idea was that the mapper would just have read that values from the class and used them to properly 'instruct' the ExtProperty I wanted to use.BTW, the solution you found seems to be the best and has no shortcomings, so I'll take that route.
Thank you for both your help and sqlalchemy itself :-)-- 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  -~--~~~~--~~--~--~---