Share

SQLObject

Tracker: Bugs

5 __connection__.style broken in .6.1 - ID: 1172892
Last Update: Settings changed ( phd )

I created a Style subclass but it didn't work. So I
changed all my Style's methods to raise an exception.
Still showed default behavior. Then I tried assigning
_style in each class -- that worked. I'd very much
like to be able to set it globally, though.


Jonathan Ellis ( ellisj ) - 2005-03-29 23:24

5

Closed

Wont Fix

Nobody/Anonymous

General

SQLObject release (specify)

Public


Comments ( 3 )




Date: 2005-08-18 01:21
Sender: viritrilbia

Logged In: YES
user_id=54785

I have encountered this problem as well (trying to use long
IDs) and I think I have figured out why it happens. When
you create a table class, it is a subclass of SQLObject and
hence an instance of MetaSQLObject. The __new__ method of
MetaSQLObject sets _connection to __connection__ if it is
unset, and then sets _style to _connection.style or
styles.defaultStyle if it is unset. This sounds good,
however...

The trick is that SQLObject itself is an instance of
MetaSQLObject, so when sqlobject is *loaded*,
SQLObject._style gets set to styles.defaultStyle. Nothing
can be done about this, since you haven't had a chance to
set __connection__ yet, let alone __connection__.style.
Then when you create table classes, since they are
subclasses of SQLObject, they inherit its _style attribute,
so MetaSQLObject.__new__ doesn't even look at _connection.style.

An even easier version of the workaround below, as long as
you are only using one style in your entire program, is to
set SQLObject._style to your desired style. This obviates
the need for an extra base class.

I think it would be best if style could be set by
connection, since the style used is really a property of the
database in question. I'm not sure how one would accomplish
this, however, if the above is indeed the problem. Maybe
MetaSQLObject.__new__ should decline to set _style if it is
not setting _connection as well?



Date: 2005-03-30 14:20
Sender: nobody

Logged In: NO

That is a nice workaround, but either dbconnection.style
should work or it should be removed...


Date: 2005-03-30 12:08
Sender: phdProject Admin

Logged In: YES
user_id=4799

Create a class that will be served as the base class for all
your tables. Assign your style to it:

class Base(SQLObject):
_style = MyStyle()

class MyTable(Base):
...


Log in to comment.

Attached File

No Files Currently Attached

Changes ( 3 )

Field Old Value Date By
status_id Open 2008-03-07 15:01 phd
resolution_id None 2008-03-07 15:01 phd
close_date - 2008-03-07 15:01 phd