[sqlalchemy] Re: broken relationship

2008-01-07 Thread Marcos Dione

On Mon, Jan 07, 2008 at 01:00:20AM -0200, Marcos Dione wrote:
 until yesterday did worked, but seems like after I upgraded to the
 new sqla 0.4.2-1 from Debian Sid, it broke this way. am I doing anything
 conceptually wrong?
 
 --
 $ sqlite3 test.sqlt
 SQLite version 3.4.2
 Enter .help for instructions
 sqlite select * from post;
 1|http://bonga.org/posts/post.html||Fist post!|This the fist post. Like the 
 fist import, but not.|2008-01-07 00:44:03|read
   ^^ this is where feed_id should not be NULL!
 sqlite select * from feed;
 1|bonga|http://bonga.org/rss.xml|1
 -- 

more info. this is with meta.echo= True:

2008-01-07 01:09:32,430 INFO sqlalchemy.engine.base.Engine.0x..14 BEGIN
2008-01-07 01:09:32,433 INFO sqlalchemy.engine.base.Engine.0x..14 INSERT INTO 
feed (name, url, active) VALUES (?, ?, ?)
2008-01-07 01:09:32,435 INFO sqlalchemy.engine.base.Engine.0x..14 ['bonga', 
'http://bonga.org/rss.xml', 1]
2008-01-07 01:09:32,438 INFO sqlalchemy.engine.base.Engine.0x..14 COMMIT
2008-01-07 01:09:32,486 INFO sqlalchemy.engine.base.Engine.0x..14 BEGIN
2008-01-07 01:09:32,494 INFO sqlalchemy.engine.base.Engine.0x..14 INSERT INTO 
post (guid, feed_id, title, content, date, state) VALUES (?, ?, ?, ?, ?, ?)
2008-01-07 01:09:32,495 INFO sqlalchemy.engine.base.Engine.0x..14 
['http://bonga.org/posts/post.html', None, 'Fist post!', 'This the fist post. 
Like the fist import, but not.', '2008-01-07 01:09:32', 'read']
2008-01-07 01:09:32,506 INFO sqlalchemy.engine.base.Engine.0x..14 COMMIT

evidently sqla is not working for me as before.

 class SQLAObject (object):
 def __init__ (self, **kwargs):
 object.__init__ (self)
 self.__dict__.update (kwargs)

I got this in IRC:

01:33  zzzeek_ styxman: updating __dict__ directly is a no no
01:33  zzzeek_ have to use setattr()

maybe is that? I'll check later.

-- 
(Not so) Random fortune:
10:22  el_machi e-squizo: es que ayer nos pasó lo impensable: estábamos por
sopletear una pc para quitarle la tierra, en lo de un amigo, y en un 
descuido el perro nos meó la computadora...

--~--~-~--~~~---~--~~
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: broken relationship

2008-01-07 Thread Marcos Dione

On Mon, Jan 07, 2008 at 03:41:22PM -0200, Marcos Dione wrote:
 On Mon, Jan 07, 2008 at 01:00:20AM -0200, Marcos Dione wrote:
  class SQLAObject (object):
  def __init__ (self, **kwargs):
  object.__init__ (self)
  self.__dict__.update (kwargs)
 
 I got this in IRC:
 
 01:33  zzzeek_ styxman: updating __dict__ directly is a no no
 01:33  zzzeek_ have to use setattr()
 
 maybe is that? I'll check later.

yes, it was. I changed the code to this and it started working
again:

class SQLAObject (object):
def __init__ (self, **kwargs):
object.__init__ (self)
for (k, v) in kwargs.items ():
setattr (self, k, v)

-- 
(Not so) Random fortune:
23:19  perrito666 yogurt2ungue: justo estoy viendo una pelicula que
demuestra en que se ha convertido #grulic
23:19  perrito666 alguna vez viste equilibrium?

--~--~-~--~~~---~--~~
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] broken relationship

2008-01-06 Thread Marcos Dione

me and my now ex-girlfriend just broke... 

sorry, couldn't help myself. it's just that I've been the whole
afternoon chasing this bug in #sqlalchemy. see the attached script. it
basically creates a Feed and a Post related with that Feed. the Feed
goes just fine in the db, but the Post goes with a NULL feed_id[1].

until yesterday did worked, but seems like after I upgraded to the
new sqla 0.4.2-1 from Debian Sid, it broke this way. am I doing anything
conceptually wrong?

--
$ sqlite3 test.sqlt
SQLite version 3.4.2
Enter .help for instructions
sqlite select * from post;
1|http://bonga.org/posts/post.html||Fist post!|This the fist post. Like the 
fist import, but not.|2008-01-07 00:44:03|read
  ^^ this is where feed_id should not be NULL!
sqlite select * from feed;
1|bonga|http://bonga.org/rss.xml|1
-- 
(Not so) Random fortune:
Cruickshank's Law of Committees: If a committee is allowed to discuss a bad idea
long enough, it will inevitably decide to implement the idea simply because so
much work has already been done on it.

--~--~-~--~~~---~--~~
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 *
from sqlalchemy.orm import mapper, relation
import mx.DateTime
import sqlalchemy.orm

class SQLAObject (object):
def __init__ (self, **kwargs):
object.__init__ (self)
self.__dict__.update (kwargs)

class Feed (SQLAObject):
pass

class Post (SQLAObject):
pass

def main ():
db= create_engine ('sqlite:///test.sqlt')
meta= MetaData (db)

feeds= Table ('feed', meta,
Column ('id', Integer, primary_key=True),
Column ('name', Unicode, index=True, unique=True),
# Column ('name', Unicode),
Column ('url', TEXT),
Column ('active', BOOLEAN),
)

posts= Table ('post', meta,
Column ('id', Integer, primary_key=True),
Column ('guid', TEXT, index=True, unique=True),
# Column ('guid', TEXT),
Column ('feed_id', Integer, ForeignKey ('feed.id')),
Column ('title', Unicode),
Column ('content', Unicode),
Column ('date', DateTime),
Column ('state', TEXT), # new, unread, later, read, deleted
)

mapper (Feed, feeds, properties=dict (
posts=relation (Post, backref='feed'),
))
mapper (Post, posts)

# create databases, for the first run
try:
meta.create_all (checkfirst=True)
except exceptions.InvalidRequestError:
meta= BoundMetaData (db)
# meta.create_all (checkfirst=True)
meta.create_all (checkfirst=False)

session= sqlalchemy.orm.create_session (bind=db)

feed= Feed (name=u'bonga', url='http://bonga.org/rss.xml', active=True)
session.save (feed)
session.flush ()

post= Post (
guid='http://bonga.org/posts/post.html',
feed=feed,
title=u'Fist post!',
content=u'This the fist post. Like the fist import, but not.',
date=mx.DateTime.now (),
state='read'
)
session.save (post)
session.flush ()
session.close ()

if __name__=='__main__':
main ()

# end


[sqlalchemy] 0.3 to 0.4 migration problem

2007-10-28 Thread Marcos Dione


hi all. I've been using sqlalchemy in one of may projects. I
followed the steps in http://www.sqlalchemy.org/trac/wiki/WhatsNewIn04,
but the I got this backtrace:

Traceback (most recent call last):
  File ./kress.py, line 664, in ?
main(sys.argv)
  File ./kress.py, line 658, in main
mainWindow= Kress (app)
  File ./kress.py, line 92, in __init__
self.fromDatabase ()
  File ./kress.py, line 109, in fromDatabase
for post in self.model.posts (self.index, self.showPosts, self.activeFeeds, 
self.filteringTags, self.textFilter):
  File 
/home/mdione/src/projects/kreissy/src/branches/multi-feed-tag/src/kress/model/kressdata.py,
 line 96, in posts
p= q.all ()
  File /usr/lib/python2.4/site-packages/sqlalchemy/orm/query.py, line 571, in 
all
return list(self)
  File /usr/lib/python2.4/site-packages/sqlalchemy/orm/query.py, line 615, in 
__iter__
context = self._compile_context()
  File /usr/lib/python2.4/site-packages/sqlalchemy/orm/query.py, line 864, in 
_compile_context

statement.append_order_by(*sql_util.ClauseAdapter(s3).copy_and_process(order_by))
  File /usr/lib/python2.4/site-packages/sqlalchemy/sql/util.py, line 232, in 
copy_and_process
self.process_list(list_)
  File /usr/lib/python2.4/site-packages/sqlalchemy/sql/util.py, line 243, in 
process_list
list_[i] = self.traverse(list_[i], clone=True)
  File /usr/lib/python2.4/site-packages/sqlalchemy/sql/visitors.py, line 56, 
in traverse
for c in t.get_children(**self.__traverse_options__):
  File /usr/lib/python2.4/site-packages/sqlalchemy/sql/expression.py, line 
1858, in get_children
return self.bindparams.values()
AttributeError: 'list' object has no attribute 'values'

the relevant code near that Query.all() is:

def posts (self, index=0, count=None, feeds=None, tags=None, search=None):
# apply filters
constraint= Post.c.state!='deleted'

# this two chunks just adds constraints by or'ing feed and tag names.
if len (feeds)0:
# or'ing feeds
# by cases
feedName= feeds[0]
if len (feeds)==1:
constraint= constraint  (Feed.c.name==feedName)  
self.query.join_to ('feed')
elif len (feeds)1:
temp= (Feed.c.name==feedName)  self.query.join_to ('feed')
for feedName in feeds[1:]:
temp= temp | (Feed.c.name==feedName)  self.query.join_to 
('feed')
constraint= constraint  temp

if len (tags)0:
tagName= tags[0]
if len (tags)==1:
constraint= constraint  (Tag.c.name==tagName)  
self.query.join_to ('tags')
elif len (tags)1:
temp= (Tag.c.name==tagName)  self.query.join_to ('tags')
for tagName in tags[1:]:
temp= temp | (Tag.c.name==tagName)  self.query.join_to 
('tags')
constraint= constraint  temp

if search is not None:
constraint= constraint  (Post.c.title.like ('%'+search+'%'))

q= self.query.offset (index)
if count is not None:
q= q.limit (count)
q= q.order_by (sqlalchemy.desc ('date'))
q= q.filter (constraint)
print self.query.compile () ---
p= q.all ()
return p

that print hightlighted there gives:

SELECT 
tag_1.id AS tag_1_id, 
tag_1.name AS tag_1_name, 
post.id AS post_id, 
post.guid AS post_guid, 
post.feed_id AS post_feed_id, 
post.title AS post_title, 
post.content AS post_content, 
post.date AS post_date, 
post.state AS post_state
FROM 
post 
LEFT OUTER JOIN post_tag AS post_tag_2 ON 
post.id = post_tag_2.post_id 
LEFT OUTER JOIN tag AS tag_1 ON 
tag_1.id = post_tag_2.tag_id 
ORDER BY 
post.oid, post_tag_2.oid


I will try to minimize the example, but I wanted you opinion in the
meanwhile.

--~--~-~--~~~---~--~~
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] why this Query API?

2007-08-24 Thread Marcos Dione


hi, I'm rather new to SQLAlchemy, using version 0.3.x right now. I
would like to know the reason why Query.filter() returns another Query
object instead of aplying in place, if there is one. an answer to this
would help me to understand better this ORM.


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