Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #801 (closed defect: fixed)

Opened 12 years ago

Last modified 10 years ago

0.9a5 - sqlalchemy quickstart model.py template incorrect

Reported by: jvanasco@… Owned by: anonymous
Priority: normal Milestone: 0.9a6
Component: Installation Version: 0.9a5
Severity: normal Keywords:
Cc:

Description

if one selects sqlalchemy as a quickstart template, one gets...

from sqlobject import *
from turbogears.database import PackageHub

hub = PackageHub("myApp")
__connection__ = hub

# class YourDataClass(SQLObject):
#     pass

from sqlalchemy.ext.activemapper import *

which needlessly calls sqlobject (if you're using sqlalchemy for id, you're likely using it for all your classes) and then references to _ _ engine _ _ are made, but it is unset

that should be more like

from sqlalchemy import *
from sqlalchemy.ext.activemapper import *

from turbogears.database import PackageEngine 
engine = __engine__ = PackageEngine("myApp")

this patch should correct it (untested though, i'm not sure how to test)- it tosses in sqlalchemy info if the identity provider is sqlalchemy, and defaults to sqlobject for everything else

Attachments

model.py.diff Download (1.0 KB) - added by anonymous 12 years ago.
identityfixed.diff Download (12.3 KB) - added by jvanasco@… 12 years ago.
does not include changes to model.py - makes identity/visit in SA usable
identity_fixed.diff Download (13.6 KB) - added by jvanasco@… 12 years ago.
Please ignore the previous version of this file. I had 2 svn cos, and i sent in a patch off the wrong one. I just tested this fixed patch on 2 maches.

Change History

Changed 12 years ago by anonymous

comment:1 Changed 12 years ago by jvanasco@…

ok. to update-

that patch will work to get SQLalchemy's required variables in place.

The default identity scheme however will not work -- i just tried a test case after patching the install

The install patch will fix the following:

  • gives you db access through _ _ engine _ _
  • makes the datatypes available

These are the errors I have found that I do not know how to fix on my own ( tied too much into the TG quickstart for me to patch )

  • tg-admin sql create does not support SQL alchemy ( will it ever ? this should perhaps be documented in the quickstart after selected sqlalchemy as the id provider )
  • the schema is incorrect -> Table 'user_group' foreign keys on table 'group'. Class 'group' is mapped to table 'tg_group'
  • i don't think that sqlalchemy can support automagic table creation from mapped classes ( i checked the docs ). I think tables must be explicitly generated via the Table() class instantiation , as created for user_group and group_permission

comment:2 Changed 12 years ago by jvanasco@…

  • Version changed from 0.9a4 to 0.9a5

updated revision to 0.9a5

comment:3 Changed 12 years ago by jvanasco@…

I'm continually updating this with errors as i find in this file:

class Permission(ActiveMapper):
    class mapping:
        __table__="permission"
        permission_id = column( Integer, primary_key=True )
        permission_name = column( Unicode(16), unique=True )
        description = column( Unicode(255) )
        
        groups = many_to_many( "Group", group_permission,
                              backref="permmissions" )

the backref 'permmissions' is a typo to 'permissions'

comment:4 Changed 12 years ago by jvanasco@…

this is purely stylistic:

as user_group and group_permission are both associative tables, i'd suggest naming them either UserGroup? or user2group - which tend to me more commonplace naming conventions for associative tables ( or just tack on _association to the end ). the naming convention as-is is a little awkward, as there are/were the tg_ tables , which suggests '_' as a word delimiter, and not a signifier of association.

comment:5 Changed 12 years ago by jvanasco@…

moving forwards...

TG_Vist does not work because it seems that ActiveMapper? is in a state of flux .

 http://groups.google.com/group/turbogears/browse_thread/thread/64cb0556a12ea7cf/a2070e25101d0297

My guess is that much of the model templating as-is will not work either.

Later tonight I'll try to patch savisit.py to work without ActiveMapper? , but people should be aware that sqlalchemy and activemapper are not in sync right now

comment:6 Changed 12 years ago by anonymous

re:

i don't think that sqlalchemy can support automagic table creation from mapped classes ( i checked the docs ). I think tables must be explicitly generated via the Table() class instantiation , as created for user_group and group_permission

I was wrong. It does, its just not documented well. The sytax to do so is correct in savisit.py

    TG_Visit.table.create()

however since ActiveMapper? is in flux, the class/table definition needs some altering to work

tbl__tgvisit = Table('tg_visit', __engine__, 
    Column('visit_key', String(40) , primary_key=True),
    Column('created', DateTime  , nullable = False ),
    Column('expiry', DateTime ),
)

class TG_Visit(object):
    table = tbl__tgvisit
    def lookup_visit( cls, visit_key ):
        return TG_Visit.get( visit_key );
    lookup_visit= classmethod(lookup_visit)

assign_mapper( TG_Visit , tbl__tgvisit )

not pretty and uses the monkeypatch in sqlalchemy, but it keeps all the rest of the code happy

also

saprovider.py is only half-ported to use the model.py classes. i'm 1/2way through a patch.. should be done shortly.

comment:7 Changed 12 years ago by jvanasco@…

Ok. here's a patch that fixes identity ( for the most part )

to note:

  • i renamed 'visit.*.model' to 'identity.*.model.visit2identity' as this is the visit - to - id table, and is more a part of identity than visit, and also configured as a part of identity
  • i disabled table creation on identity for SAp, as it would raise an error and hang the application even when i caught the exception
  • i migrated _load_class to utils.load_class in SAp
  • i did the savisit monkeypatch as i suggested above
  • SA and SO have default classes in there that should probably go, as everything is in model.py now

Changed 12 years ago by jvanasco@…

does not include changes to model.py - makes identity/visit in SA usable

Changed 12 years ago by jvanasco@…

Please ignore the previous version of this file. I had 2 svn cos, and i sent in a patch off the wrong one. I just tested this fixed patch on 2 maches.

comment:8 Changed 12 years ago by anonymous

  • Milestone set to 1.0b1

comment:9 Changed 12 years ago by kevin

This appears to be consolidated into #825.

comment:10 Changed 12 years ago by godoy

  • Status changed from new to closed
  • Resolution set to fixed

I've fixed the model generated by quickstart, what was the original bug. I'm closing this with [1376].

comment:11 Changed 12 years ago by kevin

  • Milestone changed from 1.0b1 to 0.9a6
Note: See TracTickets for help on using tickets.