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 #2359 (closed enhancement: fixed)

Opened 8 years ago

Last modified 8 years ago

[PATCH] Add emulation of SQLAlchemy Session.mapper to turbogears.database

Reported by: Chris Arndt Owned by: Chris Arndt
Priority: normal Milestone: 1.1
Component: TurboGears Version: 1.1b1
Severity: normal Keywords:
Cc: chrisz

Description (last modified by Chris Arndt) (diff)

Since Session.mapper is deprecated in SQLAlchemy >= 0.5.5 the attached patch adds code to emulate its behavior to turbogears.database following this recipe from the SA wiki (with slight enhancements):

 http://www.sqlalchemy.org/trac/wiki/UsageRecipes/SessionAwareMapper

A possible improvement would be to make the use of this code configurable through the app's config file.

Attachments

session_mapper.diff Download (2.3 KB) - added by Chris Arndt 8 years ago.
Patch for turbogears.database
session_mapper2.diff Download (4.6 KB) - added by Chris Arndt 8 years ago.
session_mapper3.diff Download (5.4 KB) - added by Chris Arndt 8 years ago.
New patch with improvements sugessted by chrisz

Change History

Changed 8 years ago by Chris Arndt

Patch for turbogears.database

comment:1 Changed 8 years ago by chrisz

+1

comment:2 Changed 8 years ago by Chris Arndt

  • Status changed from new to assigned
  • Owner set to Chris Arndt
  • Type changed from defect to enhancement
  • Description modified (diff)

I added an improved patch with the following changes:

  • session_mapper is defined regardless of whether Session.mapper is available or not, so users can choose what to import.
  • Validation of kw args to constructor of mapped objects actually works now.
  • New unit test suite

Changed 8 years ago by Chris Arndt

comment:3 Changed 8 years ago by chrisz

Makes sense. But session_mapper is now a function. We could rename it to create_session_mapper and let session_mapper be the result of the call instead, so that you can do from database import session_mapper as mapper without the need to call anything. Or at least the scoped_session parameter could have a default value of session.

comment:4 Changed 8 years ago by chrisz

session_mapper/create_session_mapper should also be added to the list of exported names at the bottom of turbogears.database.

Changed 8 years ago by Chris Arndt

New patch with improvements sugessted by chrisz

comment:5 Changed 8 years ago by Chris Arndt

Ok, I added a new patch with the suggested improvements.

comment:6 Changed 8 years ago by Chris Arndt

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

Applied in r6638.

Note: See TracTickets for help on using tickets.