[Checkins] SVN: zope.sqlalchemy/trunk/ Rename 'invalidate' to 'mark_changed'. Depend on 0.4.7dev.

Laurence Rowe l at lrowe.co.uk
Sat Jul 19 13:23:33 EDT 2008


Log message for revision 88610:
  Rename 'invalidate' to 'mark_changed'. Depend on 0.4.7dev.

Changed:
  U   zope.sqlalchemy/trunk/CHANGES.txt
  U   zope.sqlalchemy/trunk/setup.py
  U   zope.sqlalchemy/trunk/src/zope/sqlalchemy/README.txt
  U   zope.sqlalchemy/trunk/src/zope/sqlalchemy/__init__.py
  U   zope.sqlalchemy/trunk/src/zope/sqlalchemy/datamanager.py

-=-
Modified: zope.sqlalchemy/trunk/CHANGES.txt
===================================================================
--- zope.sqlalchemy/trunk/CHANGES.txt	2008-07-19 17:08:36 UTC (rev 88609)
+++ zope.sqlalchemy/trunk/CHANGES.txt	2008-07-19 17:23:32 UTC (rev 88610)
@@ -1,15 +1,28 @@
 Changes
 =======
 
+0.3 (unreleased)
+----------------
+
+Bugs fixed:
+
+* New objects added to a session did not cause a transaction join, so were not
+  committed at the end of the transaction unless the database was accessed.
+  SQLAlchemy 0.4.7 or 0.5beta3 now required.
+
+Feature changes:
+
+* For correctness and consistency with ZODB, renamed the function 'invalidate' 
+  to 'mark_changed' and the status 'invalidated' to 'changed'.
+
 0.2 (2008-06-28)
 ----------------
 
-Feature changes
-~~~~~~~~~~~~~~~
+Feature changes:
 
 * Updated to support SQLAlchemy 0.5. (0.4.6 is still supported).
 
 0.1 (2008-05-15)
 ----------------
 
-Initial public release.
+* Initial public release.

Modified: zope.sqlalchemy/trunk/setup.py
===================================================================
--- zope.sqlalchemy/trunk/setup.py	2008-07-19 17:08:36 UTC (rev 88609)
+++ zope.sqlalchemy/trunk/setup.py	2008-07-19 17:23:32 UTC (rev 88610)
@@ -52,7 +52,7 @@
 
 setup(
     name='zope.sqlalchemy',
-    version='0.2', # Remember to update __version__ in __init__.py
+    version='0.3', # Remember to update __version__ in __init__.py
     
     packages=find_packages('src'),
     package_dir = {'':'src'},
@@ -79,7 +79,7 @@
 
     install_requires=[
       'setuptools',
-      'SQLAlchemy>=0.5.0beta3dev-r4954',
+      'SQLAlchemy>=0.4.7dev', # or >=0.5b3
       'transaction',
       'zope.interface',
       ],

Modified: zope.sqlalchemy/trunk/src/zope/sqlalchemy/README.txt
===================================================================
--- zope.sqlalchemy/trunk/src/zope/sqlalchemy/README.txt	2008-07-19 17:08:36 UTC (rev 88609)
+++ zope.sqlalchemy/trunk/src/zope/sqlalchemy/README.txt	2008-07-19 17:23:32 UTC (rev 88610)
@@ -44,7 +44,7 @@
     >>> from sqlalchemy import *
     >>> from sqlalchemy.ext.declarative import declarative_base
     >>> from sqlalchemy.orm import scoped_session, sessionmaker, relation
-    >>> from zope.sqlalchemy import ZopeTransactionExtension, invalidate
+    >>> from zope.sqlalchemy import ZopeTransactionExtension
     >>> import transaction
 
 Now to define the mapper classes.
@@ -131,11 +131,11 @@
     >>> transaction.abort()
 
 By default, zope.sqlalchemy puts sessions in an 'active' state when they are
-first used. ORM write operations automatically move the session into an
-'invalidated' state. This avoids unnecessary database commits. Sometimes it
+first used. ORM write operations automatically move the session into a
+'changed' state. This avoids unnecessary database commits. Sometimes it
 is necessary to interact with the database directly through SQL. It is not
 possible to guess whether such an operation is a read or a write. Therefore we
-must manually mark the session as invalidated when manual SQL statements write
+must manually mark the session as changed when manual SQL statements write
 to the DB.
 
     >>> session = Session()
@@ -143,8 +143,8 @@
     >>> users = Base.metadata.tables['test_users']
     >>> conn.execute(users.update(users.c.name=='bob'), name='ben')
     <sqlalchemy.engine.base.ResultProxy object at ...>
-    >>> from zope.sqlalchemy import invalidate
-    >>> invalidate(session)
+    >>> from zope.sqlalchemy import mark_changed
+    >>> mark_changed(session)
     >>> transaction.commit()
     >>> session = Session()
     >>> session.query(User).all()[0].name
@@ -152,9 +152,9 @@
     >>> transaction.abort()
 
 If this is a problem you may tell the extension to place the session in the
-'invalidated' state initially.
+'changed' state initially.
 
-    >>> Session.configure(extension=ZopeTransactionExtension('invalidated'))
+    >>> Session.configure(extension=ZopeTransactionExtension('changed'))
     >>> Session.remove()
     >>> session = Session()
     >>> conn = session.connection()

Modified: zope.sqlalchemy/trunk/src/zope/sqlalchemy/__init__.py
===================================================================
--- zope.sqlalchemy/trunk/src/zope/sqlalchemy/__init__.py	2008-07-19 17:08:36 UTC (rev 88609)
+++ zope.sqlalchemy/trunk/src/zope/sqlalchemy/__init__.py	2008-07-19 17:23:32 UTC (rev 88610)
@@ -12,6 +12,7 @@
 #
 ##############################################################################
 
-__version__ = '0.2'
+__version__ = '0.3'
 
-from datamanager import ZopeTransactionExtension, invalidate
+from datamanager import ZopeTransactionExtension, mark_changed
+invalidate = mark_changed

Modified: zope.sqlalchemy/trunk/src/zope/sqlalchemy/datamanager.py
===================================================================
--- zope.sqlalchemy/trunk/src/zope/sqlalchemy/datamanager.py	2008-07-19 17:08:36 UTC (rev 88609)
+++ zope.sqlalchemy/trunk/src/zope/sqlalchemy/datamanager.py	2008-07-19 17:23:32 UTC (rev 88610)
@@ -20,8 +20,9 @@
 
 # The status of the session is stored on the connection info
 STATUS_ACTIVE = 'active' # session joined to transaction, writes allowed.
-STATUS_INVALIDATED = 'invalidated' # data has been written
+STATUS_CHANGED = 'changed' # data has been written
 STATUS_READONLY = 'readonly' # session joined to transaction, no writes allowed.
+STATUS_INVALIDATED = STATUS_CHANGED # BBB
 
 NO_SAVEPOINT_SUPPORT = set(['sqlite'])
 
@@ -160,11 +161,11 @@
         DataManager = session.twophase and TwoPhaseSessionDataManager or SessionDataManager
         zope_transaction.get().join(DataManager(session, initial_state))
 
-def invalidate(session):
+def mark_changed(session):
     """Mark a session as needing to be committed
     """
     assert _SESSION_STATE[id(session)] is not STATUS_READONLY
-    _SESSION_STATE[id(session)] = STATUS_INVALIDATED
+    _SESSION_STATE[id(session)] = STATUS_CHANGED
 
 
 class ZopeTransactionExtension(SessionExtension):
@@ -173,6 +174,7 @@
     """
     
     def __init__(self, initial_state=STATUS_ACTIVE):
+        if initial_state=='invalidated': initial_state = STATUS_CHANGED #BBB
         SessionExtension.__init__(self)
         self.initial_state = initial_state
     
@@ -183,7 +185,7 @@
         join_transaction(session, self.initial_state)
     
     def after_flush(self, session, flush_context):
-        invalidate(session)
+        mark_changed(session)
     
     def before_commit(self, session):
         assert zope_transaction.get().status == 'Committing', "Transaction must be committed by zope"



More information about the Checkins mailing list