jonhattan | 1 Jul 2007 22:08
Favicon

who creates the related table in a RelatedJoin

Hi all,

I've found a problem I've hade the chance to circumvent it but would 
like to comment it out here in order to get some feedback.

the background (that will be a recipe in the wiki):

I use to use RelatedJoins to simulate one-to-many relations without the 
pain to add a foreignkey field for each relation.
Consider having a Telephone class and several clases that are naturally 
many-to-one related with telephone numbers. The tipical one-to-many 
aproach is:

class Telephone(SQLObject):
    number = StringCol()
    type = EnumCol(enumValues=['fax', 'line', 'movil'])
    person = ForeignKey('Person')
    entity = ForeignKey('Entity')

class Person(SQLObject):
    name = StringCol()
    t = MultipleJoin('Telephone')

class Entity(SQLObject):
    name = StringCol()
    t = MultipleJoin('Telephone')

So we have an ugly telephones table with two fk columns that should be 
mutually exclusive at a higher abstraction level than sql, but nothing 
constraints us to create a
(Continue reading)

Oleg Broytmann | 1 Jul 2007 22:17
X-Face
Picon
Favicon

Re: who creates the related table in a RelatedJoin

On Sun, Jul 01, 2007 at 09:08:39PM +0100, jonhattan wrote:
> So I have two questions.
> 
> first is, shouldn't it work with the last class definition I've shown?

   No, RelatedJoin was designed to be used symmetrically; you have to have
two RelatedJoins pointing to each other.

> second, could SQLObject create the table on first RelatedJoin it found, 
> instead of on the one resulting on applying the alphabetical sort?

   Currently no, but you can try to extend SQLObject. Patches (that work)
will be gladly accepted.

Oleg.
--

-- 
     Oleg Broytmann            http://phd.pp.ru/            phd <at> phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
Humberto Diogenes | 4 Jul 2007 04:37
Picon
Favicon

Re: sqlite and threads - bug?

Hi, guys!

   I was just sending a new e-mail to the list when I saw this thread.
   I was having problems recently with sqlobject+sqlite in CherryPy  
and Apache (traceback attached), and noticed they started after a  
change from sqlobject.sqlite.sqliteconnection.SQLiteConnection (which  
was issuing deprecation warnings) to sqlobject.connectionForUri  
(recommended by those same warnings).
   Anyway, after I changed back to using the deprecated function it  
magically worked again.
   I then went to look at the source code, to see if there was  
anything different in connectionForURI. I saw that it tries to do  
some caching, and ends with this:

         #  <at>  <at> : Do we care if we clobber another connection?
         self.cachedURIs[uri] = conn
         return conn

   Can someone please tell me if connectionForURI is really doing  
what it was supposed to do?

Traceback (most recent call last):
  File "/usr/lib/python2.4/site-packages/cherrypy/_cphttptools.py", line 105, in _run
    self.main()
  File "/usr/lib/python2.4/site-packages/cherrypy/_cphttptools.py", line 254, in main
    body = page_handler(*virtual_path, **self.params)
  File "./servidor.py", line 275, in listar
    dados = [dict(documento_id=f.documento_id,
(Continue reading)

Oleg Broytmann | 4 Jul 2007 09:08
X-Face
Picon
Favicon

Re: sqlite and threads - bug?

On Tue, Jul 03, 2007 at 11:37:40PM -0300, Humberto Diogenes wrote:
>         #  <at>  <at> : Do we care if we clobber another connection?
>         self.cachedURIs[uri] = conn

   Does it help if you coment out this?

Oleg.
--

-- 
     Oleg Broytmann            http://phd.pp.ru/            phd <at> phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
Brian Cole | 4 Jul 2007 16:44
Picon
Favicon

Column name can not be the same as table name?

Hello All,

Just started using SQLObject yesterday, so if I made a rookie mistake
please tell me. It appears SQLObject doesn't allow me to have the same
column name as my table name. Here is the MySQL table definition:
CREATE TABLE `sysname` (
`sysname_id` int(11) NOT NULL auto_increment,
`sysname` varchar(64) NOT NULL,
PRIMARY KEY  (`sysname_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

And the corresponding SQLObject code:
class Sysname(SQLObject):
    class sqlmeta:
        fromDatabase = True
        idName = "sysname_id"

    def getSysnameID(cls):
        sysname = platform.system()
        for s in cls.selectBy(sysname=sysname):
            return s.id

        return cls(sysname=sysname).id
    getSysnameID = classmethod(getSysnameID)

print Sysname.getSysnameID()

I get the following traceback from SQLObject:
Traceback (most recent call last):
  File "knightly/machine.py", line 22, in ?
(Continue reading)

Oleg Broytmann | 4 Jul 2007 17:50
X-Face
Picon
Favicon

Re: Column name can not be the same as table name?

On Wed, Jul 04, 2007 at 08:44:15AM -0600, Brian Cole wrote:
> CREATE TABLE `sysname` (
> `sysname_id` int(11) NOT NULL auto_increment,
> `sysname` varchar(64) NOT NULL,
> PRIMARY KEY  (`sysname_id`)
> ) ENGINE=InnoDB DEFAULT CHARSET=utf8
> 
> '_SO_class_'+column.foreignKey).q.id
> TypeError: cannot concatenate 'str' and 'NoneType' objects

   I suspect SQLObject has problems getting column decriptions from the
database (due to fromDatabase). To start debugging print Sysname.sqlmeta.columns
- do they look right?

Oleg.
--

-- 
     Oleg Broytmann            http://phd.pp.ru/            phd <at> phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
bernhard.maeder | 5 Jul 2007 10:17
Picon
Favicon

Creating more sqlobjects in _create()

Hello all

I'm experiencing frequent deadlocks in my cherrypy/sqlobject multithreaded server application. I'm unable to reproduce the error in a small-scale example yet, but one thing I noticed is, that it might be related to me creating other sqlobjects in an overwritten _create() function.

What I see is that various threads try to acquire a threadSafeMethod decorator's lock, originating from various places:

...
File "/usr/lib/python2.4/site-packages/sqlobject/sresults.py", line 165, in __iter__
return iter(list(self.lazyIter()))
File "/usr/lib/python2.4/site-packages/sqlobject/dbconnection.py", line 804, in next
obj = self.select.sourceClass.get(result[0], selectResults=result[1:], connection=self.dbconn)
File "/usr/lib/python2.4/site-packages/sqlobject/main.py", line 915, in get
val = cls(_SO_fetch_no_create=1)
File "/usr/lib/python2.4/site-packages/sqlobject/declarative.py", line 92, in _wrapper
lock.acquire()
File "threading.py", line 100, in acquire
rc = self.__block.acquire(blocking)

And one thread is pending on the cache's lock:

...
File "/usr/lib/python2.4/site-packages/sqlobject/declarative.py", line 94, in _wrapper
return fn(self, *args, **kwargs)
File "/usr/lib/python2.4/site-packages/sqlobject/main.py", line 1214, in __init__
self._create(id, **kw)
File "/usr/lib/python2.4/site-packages/sqlobject/main.py", line 1245, in _create
self._SO_finishCreate(id)
File "/usr/lib/python2.4/site-packages/sqlobject/main.py", line 1271, in _SO_finishCreate
cache.created(id, self.__class__, self)
File "/usr/lib/python2.4/site-packages/sqlobject/cache.py", line 300, in created
self.caches[cls.__name__].created(id, obj)
File "/usr/lib/python2.4/site-packages/sqlobject/cache.py", line 177, in created
self.cull()
File "/usr/lib/python2.4/site-packages/sqlobject/cache.py", line 190, in cull
self.lock.acquire()

.. originating from a certain _create function (hence my assumption).

My create() is looking quite straight-forward, something like this:

class MyClass(sqlobject):
foo = ForeignKey('OtherClass', default=None)
bar = ForeignKey('OtherClass', default=None)

def _create(self, *args, **kw):
# Create the object
super(MyClass, self)._create(*args, **kw)

# Create other object
self.foo = OtherClass()
self.bar = OtherClass()

So, my question is: is this problematic, and, if yes, what other ways are there to do it?

Thanks a million
Bernhard


... and, sorry for the mess:
___________________________________________________________________

Disclaimer:


Diese Mitteilung ist nur fuer die Empfaengerin / den Empfaenger bestimmt.

Fuer den Fall, dass sie von nichtberechtigten Personen empfangen wird, bitten wir diese hoeflich, die Mitteilung an die ZKB zurueckzusenden und anschliessend die Mitteilung mit allen Anhaengen sowie allfaellige Kopien zu vernichten bzw. zu loeschen. Der Gebrauch der Information ist verboten.


This message is intended only for the named recipient and may contain confidential or privileged information.

If you have received it in error, please advise the sender by return e-mail and delete this message and any attachments. Any unauthorised use or dissemination of this information is strictly prohibited.

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Oleg Broytmann | 5 Jul 2007 10:55
X-Face
Picon
Favicon

Re: Creating more sqlobjects in _create()

On Thu, Jul 05, 2007 at 10:17:31AM +0200, bernhard.maeder <at> zkb.ch wrote:
> I'm experiencing frequent deadlocks in my cherrypy/sqlobject multithreaded
> server application. I'm unable to reproduce the error in a small-scale
> example yet, but one thing I noticed is, that it might be related to me
> creating other sqlobjects in an overwritten _create() function.
> 
> What I see is that various threads try to acquire a threadSafeMethod
> decorator's lock, originating from various places:

   Are they different locks? And what are the error messages?

Oleg.
--

-- 
     Oleg Broytmann            http://phd.pp.ru/            phd <at> phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
bernhard.maeder | 5 Jul 2007 11:22
Picon
Favicon

Antwort: Re: Creating more sqlobjects in _create()

Hi Oleg, thanks for your response

> On Thu, Jul 05, 2007 at 10:17:31AM +0200, bernhard.maeder <at> zkb.ch wrote:
> > I'm experiencing frequent deadlocks in my cherrypy/sqlobject multithreaded
> > server application. I'm unable to reproduce the error in a small-scale
> > example yet, but one thing I noticed is, that it might be related to me
> > creating other sqlobjects in an overwritten _create() function.
> >
> > What I see is that various threads try to acquire a threadSafeMethod
> > decorator's lock, originating from various places:
>
>    Are they different locks?

I don't know, is there an easy way to tell? All I can see at the moment are the stack traces I have posted.

The accesses are made in different threads, to objects of the same class (MyClass in my example). One locks while resolving a ForeignKey in _SO_foreignKey(), one locks in _SO_finishCreate() and the third one in the selectresult's __iter__().

> And what are the error messages?

I have none, the application just locks. Or, more precisely: calls to sqlobject lock, while other parts of the application still work.

Bernhard

___________________________________________________________________

Disclaimer:


Diese Mitteilung ist nur fuer die Empfaengerin / den Empfaenger bestimmt.

Fuer den Fall, dass sie von nichtberechtigten Personen empfangen wird, bitten wir diese hoeflich, die Mitteilung an die ZKB zurueckzusenden und anschliessend die Mitteilung mit allen Anhaengen sowie allfaellige Kopien zu vernichten bzw. zu loeschen. Der Gebrauch der Information ist verboten.


This message is intended only for the named recipient and may contain confidential or privileged information.

If you have received it in error, please advise the sender by return e-mail and delete this message and any attachments. Any unauthorised use or dissemination of this information is strictly prohibited.

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Oleg Broytmann | 5 Jul 2007 11:31
X-Face
Picon
Favicon

Re: Antwort: Re: Creating more sqlobjects in _create()

On Thu, Jul 05, 2007 at 11:22:36AM +0200, bernhard.maeder <at> zkb.ch wrote:
> The accesses are made in different threads, to objects of the same class
> (MyClass in my example). One locks while resolving a ForeignKey in
> _SO_foreignKey(), one locks in _SO_finishCreate() and the third one in the
> selectresult's __iter__().

   Can you do an experiment - create objects of OtherClass outside of
_create() and assign them to foreign keys after the object has been fully
created?

Oleg.
--

-- 
     Oleg Broytmann            http://phd.pp.ru/            phd <at> phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

Gmane