<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[12569] CalendarServer/trunk/txdav/common/datastore/sql.py</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/12569">12569</a></dd>
<dt>Author</dt> <dd>wsanchez@apple.com</dd>
<dt>Date</dt> <dd>2014-02-04 17:02:28 -0800 (Tue, 04 Feb 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Clean up logging, and some lint errors.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunktxdavcommondatastoresqlpy">CalendarServer/trunk/txdav/common/datastore/sql.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunktxdavcommondatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/datastore/sql.py (12568 => 12569)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/sql.py        2014-02-05 00:48:02 UTC (rev 12568)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py        2014-02-05 01:02:28 UTC (rev 12569)
</span><span class="lines">@@ -103,8 +103,8 @@
</span><span class="cx"> # Labels used to identify the class of resource being modified, so that
</span><span class="cx"> # notification systems can target the correct application
</span><span class="cx"> NotifierPrefixes = {
</span><del>-    ECALENDARTYPE : &quot;CalDAV&quot;,
-    EADDRESSBOOKTYPE : &quot;CardDAV&quot;,
</del><ins>+    ECALENDARTYPE: &quot;CalDAV&quot;,
+    EADDRESSBOOKTYPE: &quot;CardDAV&quot;,
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> class CommonDataStore(Service, object):
</span><span class="lines">@@ -144,7 +144,8 @@
</span><span class="cx"> 
</span><span class="cx">     implements(ICalendarStore)
</span><span class="cx"> 
</span><del>-    def __init__(self,
</del><ins>+    def __init__(
+        self,
</ins><span class="cx">         sqlTxnFactory,
</span><span class="cx">         notifierFactories,
</span><span class="cx">         directoryService,
</span><span class="lines">@@ -189,8 +190,10 @@
</span><span class="cx">         self._newTransactionCallbacks = set()
</span><span class="cx"> 
</span><span class="cx">         if cacheQueries:
</span><del>-            self.queryCacher = QueryCacher(cachePool=cachePool,
-                cacheExpireSeconds=cacheExpireSeconds)
</del><ins>+            self.queryCacher = QueryCacher(
+                cachePool=cachePool,
+                cacheExpireSeconds=cacheExpireSeconds
+            )
</ins><span class="cx">         else:
</span><span class="cx">             self.queryCacher = None
</span><span class="cx"> 
</span><span class="lines">@@ -439,17 +442,33 @@
</span><span class="cx">     def _installLogTimer(self):
</span><span class="cx">         def _logTransactionWait():
</span><span class="cx">             if self.txn is not None:
</span><del>-                log.error(&quot;Transaction wait: %r, Statements: %d, IUDs: %d, Statement: %s&quot; % (self.txn, self.txn.statementCount, self.txn.iudCount, self.txn.currentStatement if self.txn.currentStatement else &quot;None&quot;,))
-                self.delayedLog = self.callLater(self.logTimerSeconds, _logTransactionWait)
</del><ins>+                log.error(
+                    &quot;Transaction wait: {self.txn}, &quot;
+                    &quot;Statements: {self.txn.statementCount!d}, &quot;
+                    &quot;IUDs: {self.txn.iudCount!d}, &quot;
+                    &quot;Statement: {self.txn.currentStatement}&quot;,
+                    self=self
+                )
+                self.delayedLog = self.callLater(
+                    self.logTimerSeconds, _logTransactionWait
+                )
</ins><span class="cx"> 
</span><span class="cx">         if self.logTimerSeconds:
</span><del>-            self.delayedLog = self.callLater(self.logTimerSeconds, _logTransactionWait)
</del><ins>+            self.delayedLog = self.callLater(
+                self.logTimerSeconds, _logTransactionWait
+            )
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def _installTimeout(self):
</span><span class="cx">         def _forceAbort():
</span><span class="cx">             if self.txn is not None:
</span><del>-                log.error(&quot;Transaction abort too long: %r, Statements: %d, IUDs: %d, Statement: %s&quot; % (self.txn, self.txn.statementCount, self.txn.iudCount, self.txn.currentStatement if self.txn.currentStatement else &quot;None&quot;,))
</del><ins>+                log.error(
+                    &quot;Transaction abort too long: {self.txn}, &quot;
+                    &quot;Statements: {self.txn.statementCount!d}, &quot;
+                    &quot;IUDs: {self.txn.iudCount!d}, &quot;
+                    &quot;Statement: {self.txn.currentStatement}&quot;,
+                    self=self
+                )
</ins><span class="cx">                 self.delayedTimeout = None
</span><span class="cx">                 if self.delayedLog:
</span><span class="cx">                     self.delayedLog.cancel()
</span><span class="lines">@@ -457,7 +476,9 @@
</span><span class="cx">                 self.txn.timeout()
</span><span class="cx"> 
</span><span class="cx">         if self.timeoutSeconds:
</span><del>-            self.delayedTimeout = self.callLater(self.timeoutSeconds, _forceAbort)
</del><ins>+            self.delayedTimeout = self.callLater(
+                self.timeoutSeconds, _forceAbort
+            )
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -469,9 +490,11 @@
</span><span class="cx"> 
</span><span class="cx">     id = 0
</span><span class="cx"> 
</span><del>-    def __init__(self, store, sqlTxn,
-                 enableCalendars, enableAddressBooks,
-                 notifierFactories, label, migrating=False, disableCache=False):
</del><ins>+    def __init__(
+        self, store, sqlTxn,
+        enableCalendars, enableAddressBooks,
+        notifierFactories, label, migrating=False, disableCache=False
+    ):
</ins><span class="cx">         self._store = store
</span><span class="cx">         self._calendarHomes = {}
</span><span class="cx">         self._addressbookHomes = {}
</span><span class="lines">@@ -546,7 +569,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _calendarserver(cls): #@NoSelf
</del><ins>+    def _calendarserver(cls):
</ins><span class="cx">         cs = schema.CALENDARSERVER
</span><span class="cx">         return Select(
</span><span class="cx">             [cs.VALUE, ],
</span><span class="lines">@@ -583,7 +606,7 @@
</span><span class="cx">         ).on(self)
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def _determineMemo(self, storeType, uid, create=False): #@UnusedVariable
</del><ins>+    def _determineMemo(self, storeType, uid, create=False):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Determine the memo dictionary to use for homeWithUID.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -663,7 +686,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _insertAPNSubscriptionQuery(cls): #@NoSelf
</del><ins>+    def _insertAPNSubscriptionQuery(cls):
</ins><span class="cx">         apn = schema.APN_SUBSCRIPTIONS
</span><span class="cx">         return Insert({apn.TOKEN: Parameter(&quot;token&quot;),
</span><span class="cx">                        apn.RESOURCE_KEY: Parameter(&quot;resourceKey&quot;),
</span><span class="lines">@@ -674,7 +697,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _updateAPNSubscriptionQuery(cls): #@NoSelf
</del><ins>+    def _updateAPNSubscriptionQuery(cls):
</ins><span class="cx">         apn = schema.APN_SUBSCRIPTIONS
</span><span class="cx">         return Update({apn.MODIFIED: Parameter(&quot;modified&quot;),
</span><span class="cx">                        apn.SUBSCRIBER_GUID: Parameter(&quot;subscriber&quot;),
</span><span class="lines">@@ -685,7 +708,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _selectAPNSubscriptionQuery(cls): #@NoSelf
</del><ins>+    def _selectAPNSubscriptionQuery(cls):
</ins><span class="cx">         apn = schema.APN_SUBSCRIPTIONS
</span><span class="cx">         return Select([apn.MODIFIED, apn.SUBSCRIBER_GUID], From=apn,
</span><span class="cx">                 Where=(
</span><span class="lines">@@ -729,7 +752,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _removeAPNSubscriptionQuery(cls): #@NoSelf
</del><ins>+    def _removeAPNSubscriptionQuery(cls):
</ins><span class="cx">         apn = schema.APN_SUBSCRIPTIONS
</span><span class="cx">         return Delete(From=apn,
</span><span class="cx">                       Where=(apn.TOKEN == Parameter(&quot;token&quot;)).And(
</span><span class="lines">@@ -742,7 +765,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _purgeOldAPNSubscriptionQuery(cls): #@NoSelf
</del><ins>+    def _purgeOldAPNSubscriptionQuery(cls):
</ins><span class="cx">         apn = schema.APN_SUBSCRIPTIONS
</span><span class="cx">         return Delete(From=apn,
</span><span class="cx">                       Where=(apn.MODIFIED &lt; Parameter(&quot;olderThan&quot;)))
</span><span class="lines">@@ -754,7 +777,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _apnSubscriptionsByTokenQuery(cls): #@NoSelf
</del><ins>+    def _apnSubscriptionsByTokenQuery(cls):
</ins><span class="cx">         apn = schema.APN_SUBSCRIPTIONS
</span><span class="cx">         return Select([apn.RESOURCE_KEY, apn.MODIFIED, apn.SUBSCRIBER_GUID],
</span><span class="cx">                       From=apn, Where=apn.TOKEN == Parameter(&quot;token&quot;))
</span><span class="lines">@@ -765,7 +788,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _apnSubscriptionsByKeyQuery(cls): #@NoSelf
</del><ins>+    def _apnSubscriptionsByKeyQuery(cls):
</ins><span class="cx">         apn = schema.APN_SUBSCRIPTIONS
</span><span class="cx">         return Select([apn.TOKEN, apn.SUBSCRIBER_GUID],
</span><span class="cx">                       From=apn, Where=apn.RESOURCE_KEY == Parameter(&quot;resourceKey&quot;))
</span><span class="lines">@@ -776,7 +799,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _apnSubscriptionsBySubscriberQuery(cls): #@NoSelf
</del><ins>+    def _apnSubscriptionsBySubscriberQuery(cls):
</ins><span class="cx">         apn = schema.APN_SUBSCRIPTIONS
</span><span class="cx">         return Select([apn.TOKEN, apn.RESOURCE_KEY, apn.MODIFIED, apn.USER_AGENT, apn.IP_ADDR],
</span><span class="cx">                       From=apn, Where=apn.SUBSCRIBER_GUID == Parameter(&quot;subscriberGUID&quot;))
</span><span class="lines">@@ -789,7 +812,7 @@
</span><span class="cx">     # Create IMIP token
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _insertIMIPTokenQuery(cls): #@NoSelf
</del><ins>+    def _insertIMIPTokenQuery(cls):
</ins><span class="cx">         imip = schema.IMIP_TOKENS
</span><span class="cx">         return Insert({imip.TOKEN: Parameter(&quot;token&quot;),
</span><span class="cx">                        imip.ORGANIZER: Parameter(&quot;organizer&quot;),
</span><span class="lines">@@ -819,7 +842,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _selectIMIPTokenByTokenQuery(cls): #@NoSelf
</del><ins>+    def _selectIMIPTokenByTokenQuery(cls):
</ins><span class="cx">         imip = schema.IMIP_TOKENS
</span><span class="cx">         return Select([imip.ORGANIZER, imip.ATTENDEE, imip.ICALUID], From=imip,
</span><span class="cx">                       Where=(imip.TOKEN == Parameter(&quot;token&quot;)))
</span><span class="lines">@@ -832,7 +855,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _selectIMIPTokenQuery(cls): #@NoSelf
</del><ins>+    def _selectIMIPTokenQuery(cls):
</ins><span class="cx">         imip = schema.IMIP_TOKENS
</span><span class="cx">         return Select([imip.TOKEN], From=imip,
</span><span class="cx">                       Where=(imip.ORGANIZER == Parameter(&quot;organizer&quot;)).And(
</span><span class="lines">@@ -841,7 +864,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _updateIMIPTokenQuery(cls): #@NoSelf
</del><ins>+    def _updateIMIPTokenQuery(cls):
</ins><span class="cx">         imip = schema.IMIP_TOKENS
</span><span class="cx">         return Update({imip.ACCESSED: utcNowSQL, },
</span><span class="cx">                       Where=(imip.ORGANIZER == Parameter(&quot;organizer&quot;)).And(
</span><span class="lines">@@ -865,7 +888,7 @@
</span><span class="cx"> 
</span><span class="cx">     # Remove IMIP token
</span><span class="cx">     @classproperty
</span><del>-    def _removeIMIPTokenQuery(cls): #@NoSelf
</del><ins>+    def _removeIMIPTokenQuery(cls):
</ins><span class="cx">         imip = schema.IMIP_TOKENS
</span><span class="cx">         return Delete(From=imip,
</span><span class="cx">                       Where=(imip.TOKEN == Parameter(&quot;token&quot;)))
</span><span class="lines">@@ -877,7 +900,7 @@
</span><span class="cx"> 
</span><span class="cx">     # Purge old IMIP tokens
</span><span class="cx">     @classproperty
</span><del>-    def _purgeOldIMIPTokensQuery(cls): #@NoSelf
</del><ins>+    def _purgeOldIMIPTokensQuery(cls):
</ins><span class="cx">         imip = schema.IMIP_TOKENS
</span><span class="cx">         return Delete(From=imip,
</span><span class="cx">                       Where=(imip.ACCESSED &lt; Parameter(&quot;olderThan&quot;)))
</span><span class="lines">@@ -977,18 +1000,20 @@
</span><span class="cx">         # tests.  It should have more direct test coverage.
</span><span class="cx"> 
</span><span class="cx">         # TODO: we should really have a list of acceptable exceptions for
</span><del>-        # failure and not blanket catch, but that involves more knowledge of the
-        # database driver in use than we currently possess at this layer.
</del><ins>+        # failure and not blanket catch, but that involves more knowledge of
+        # the database driver in use than we currently possess at this layer.
</ins><span class="cx">         block = self._sqlTxn.commandBlock()
</span><span class="cx">         sp = self._savepoint()
</span><span class="cx">         failuresToMaybeLog = []
</span><ins>+
</ins><span class="cx">         def end():
</span><span class="cx">             block.end()
</span><span class="cx">             for f in failuresToMaybeLog:
</span><span class="cx">                 # TODO: direct tests, to make sure error logging
</span><span class="cx">                 # happens correctly in all cases.
</span><del>-                log.error(f)
</del><ins>+                log.error(&quot;in subTransaction()&quot;, failure=f)
</ins><span class="cx">             raise AllRetriesFailed()
</span><ins>+
</ins><span class="cx">         triesLeft = retries
</span><span class="cx">         try:
</span><span class="cx">             while True:
</span><span class="lines">@@ -1024,9 +1049,9 @@
</span><span class="cx">             # and only that case - acquire() or release() or commandBlock() may
</span><span class="cx">             # raise an AlreadyFinishedError (either synchronously, or in the
</span><span class="cx">             # case of the first two, possibly asynchronously as well).  We can
</span><del>-            # safely ignore this error, because it can't have any effect on what
-            # gets written; our caller will just get told that it failed in a
-            # way they have to be prepared for anyway.
</del><ins>+            # safely ignore this error, because it can't have any effect on
+            # what gets written; our caller will just get told that it failed
+            # in a way they have to be prepared for anyway.
</ins><span class="cx">             end()
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -1044,7 +1069,7 @@
</span><span class="cx">         if self._store.logLabels:
</span><span class="cx">             a = (&quot;-- Label: %s\n&quot; % (self._label.replace(&quot;%&quot;, &quot;%%&quot;),) + a[0],) + a[1:]
</span><span class="cx">         if self._store.logSQL:
</span><del>-            log.error(&quot;SQL: %r %r&quot; % (a, kw,))
</del><ins>+            log.error(&quot;SQL: {a!r} {kw!r}&quot;, a=a, kw=kw)
</ins><span class="cx">         results = None
</span><span class="cx">         try:
</span><span class="cx">             results = (yield self._sqlTxn.execSQL(*a, **kw))
</span><span class="lines">@@ -1563,13 +1588,18 @@
</span><span class="cx">     # External (cross-pod) sharing - entry point is the sharee's home collection.
</span><span class="cx">     #
</span><span class="cx">     @inlineCallbacks
</span><del>-    def processExternalInvite(self, ownerUID, ownerRID, ownerName, shareUID, bindMode, summary, copy_invite_properties, supported_components=None):
</del><ins>+    def processExternalInvite(
+        self, ownerUID, ownerRID, ownerName, shareUID, bindMode, summary,
+        copy_invite_properties, supported_components=None
+    ):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         External invite received.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         # Get the owner home - create external one if not present
</span><del>-        ownerHome = yield self._txn.homeWithUID(self._homeType, ownerUID, create=True)
</del><ins>+        ownerHome = yield self._txn.homeWithUID(
+            self._homeType, ownerUID, create=True
+        )
</ins><span class="cx">         if ownerHome is None or not ownerHome.external():
</span><span class="cx">             raise ExternalShareFailed(&quot;Invalid owner UID: {}&quot;.format(ownerUID))
</span><span class="cx"> 
</span><span class="lines">@@ -1577,29 +1607,48 @@
</span><span class="cx">         ownerView = yield ownerHome.childWithExternalID(ownerRID)
</span><span class="cx">         if ownerView is None:
</span><span class="cx">             try:
</span><del>-                ownerView = yield ownerHome.createChildWithName(ownerName, externalID=ownerRID)
</del><ins>+                ownerView = yield ownerHome.createChildWithName(
+                    ownerName, externalID=ownerRID
+                )
</ins><span class="cx">             except HomeChildNameAlreadyExistsError:
</span><del>-                # This is odd - it means we possibly have a left over sharer collection which the sharer likely removed
-                # and re-created with the same name but now it has a different externalID and is not found by the initial
-                # query. What we do is check to see whether any shares still reference the old ID - if they do we are hosed.
-                # If not, we can remove the old item and create a new one.
</del><ins>+                # This is odd - it means we possibly have a left over sharer
+                # collection which the sharer likely removed and re-created
+                # with the same name but now it has a different externalID and
+                # is not found by the initial query. What we do is check to see
+                # whether any shares still reference the old ID - if they do we
+                # are hosed. If not, we can remove the old item and create a new one.
</ins><span class="cx">                 oldOwnerView = yield ownerHome.childWithName(ownerName)
</span><span class="cx">                 invites = yield oldOwnerView.sharingInvites()
</span><span class="cx">                 if len(invites) != 0:
</span><del>-                    log.error(&quot;External invite collection name is present with a different externalID and still has shares&quot;)
</del><ins>+                    log.error(
+                        &quot;External invite collection name is present with a &quot;
+                        &quot;different externalID and still has shares&quot;
+                    )
</ins><span class="cx">                     raise
</span><del>-                log.error(&quot;External invite collection name is present with a different externalID - trying to fix&quot;)
</del><ins>+                log.error(
+                    &quot;External invite collection name is present with a &quot;
+                    &quot;different externalID - trying to fix&quot;
+                )
</ins><span class="cx">                 yield ownerHome.removeExternalChild(oldOwnerView)
</span><del>-                ownerView = yield ownerHome.createChildWithName(ownerName, externalID=ownerRID)
</del><ins>+                ownerView = yield ownerHome.createChildWithName(
+                    ownerName, externalID=ownerRID
+                )
</ins><span class="cx"> 
</span><del>-            if supported_components is not None and hasattr(ownerView, &quot;setSupportedComponents&quot;):
</del><ins>+            if (
+                supported_components is not None and
+                hasattr(ownerView, &quot;setSupportedComponents&quot;)
+            ):
</ins><span class="cx">                 yield ownerView.setSupportedComponents(supported_components)
</span><span class="cx"> 
</span><span class="cx">         # Now carry out the share operation
</span><span class="cx">         if bindMode == _BIND_MODE_DIRECT:
</span><del>-            shareeView = yield ownerView.directShareWithUser(self.uid(), shareName=shareUID)
</del><ins>+            shareeView = yield ownerView.directShareWithUser(
+                self.uid(), shareName=shareUID
+            )
</ins><span class="cx">         else:
</span><del>-            shareeView = yield ownerView.inviteUserToShare(self.uid(), bindMode, summary, shareName=shareUID)
</del><ins>+            shareeView = yield ownerView.inviteUserToShare(
+                self.uid(), bindMode, summary, shareName=shareUID
+            )
</ins><span class="cx"> 
</span><span class="cx">         shareeView.setInviteCopyProperties(copy_invite_properties)
</span><span class="cx"> 
</span><span class="lines">@@ -1623,14 +1672,17 @@
</span><span class="cx">         # Now carry out the share operation
</span><span class="cx">         yield ownerView.uninviteUserFromShare(self.uid())
</span><span class="cx"> 
</span><del>-        # See if there are any references to the external share - if not remove it
</del><ins>+        # See if there are any references to the external share. If not,
+        # remove it
</ins><span class="cx">         invites = yield ownerView.sharingInvites()
</span><span class="cx">         if len(invites) == 0:
</span><span class="cx">             yield ownerHome.removeExternalChild(ownerView)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def processExternalReply(self, ownerUID, shareeUID, shareUID, bindStatus, summary=None):
</del><ins>+    def processExternalReply(
+        self, ownerUID, shareeUID, shareUID, bindStatus, summary=None
+    ):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         External invite received.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -1640,7 +1692,9 @@
</span><span class="cx">         # Get the owner home - create external one if not present
</span><span class="cx">         shareeHome = yield self._txn.homeWithUID(self._homeType, shareeUID)
</span><span class="cx">         if shareeHome is None or not shareeHome.external():
</span><del>-            raise ExternalShareFailed(&quot;Invalid sharee UID: {}&quot;.format(shareeUID))
</del><ins>+            raise ExternalShareFailed(
+                &quot;Invalid sharee UID: {}&quot;.format(shareeUID)
+            )
</ins><span class="cx"> 
</span><span class="cx">         # Try to find owner calendar via its external id
</span><span class="cx">         shareeView = yield shareeHome.anyObjectWithShareUID(shareUID)
</span><span class="lines">@@ -1726,7 +1780,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _homeColumnsFromOwnerQuery(cls): #@NoSelf
</del><ins>+    def _homeColumnsFromOwnerQuery(cls):
</ins><span class="cx">         home = cls._homeSchema
</span><span class="cx">         return Select(
</span><span class="cx">             cls.homeColumns(),
</span><span class="lines">@@ -1736,7 +1790,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _ownerFromResourceID(cls): #@NoSelf
</del><ins>+    def _ownerFromResourceID(cls):
</ins><span class="cx">         home = cls._homeSchema
</span><span class="cx">         return Select([home.OWNER_UID],
</span><span class="cx">                       From=home,
</span><span class="lines">@@ -1744,7 +1798,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _metaDataQuery(cls): #@NoSelf
</del><ins>+    def _metaDataQuery(cls):
</ins><span class="cx">         metadata = cls._homeMetaDataSchema
</span><span class="cx">         return Select(cls.metadataColumns(),
</span><span class="cx">                       From=metadata,
</span><span class="lines">@@ -2006,7 +2060,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _dataVersionQuery(cls): #@NoSelf
</del><ins>+    def _dataVersionQuery(cls):
</ins><span class="cx">         ch = cls._homeSchema
</span><span class="cx">         return Select(
</span><span class="cx">             [ch.DATAVERSION], From=ch,
</span><span class="lines">@@ -2146,7 +2200,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _syncTokenQuery(cls): #@NoSelf
</del><ins>+    def _syncTokenQuery(cls):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL Select statement to find the sync token.
</span><span class="cx"> 
</span><span class="lines">@@ -2212,7 +2266,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _changesQuery(cls): #@NoSelf
</del><ins>+    def _changesQuery(cls):
</ins><span class="cx">         bind = cls._bindSchema
</span><span class="cx">         rev = cls._revisionsSchema
</span><span class="cx">         return Select(
</span><span class="lines">@@ -2406,12 +2460,12 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _resourceByUIDQuery(cls): #@NoSelf
</del><ins>+    def _resourceByUIDQuery(cls):
</ins><span class="cx">         return cls._objectResourceQuery(checkBindMode=False)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _resourceByUIDBindQuery(cls): #@NoSelf
</del><ins>+    def _resourceByUIDBindQuery(cls):
</ins><span class="cx">         return cls._objectResourceQuery(checkBindMode=True)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -2472,7 +2526,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _quotaQuery(cls): #@NoSelf
</del><ins>+    def _quotaQuery(cls):
</ins><span class="cx">         meta = cls._homeMetaDataSchema
</span><span class="cx">         return Select(
</span><span class="cx">             [meta.QUOTA_USED_BYTES], From=meta,
</span><span class="lines">@@ -2489,7 +2543,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _preLockResourceIDQuery(cls): #@NoSelf
</del><ins>+    def _preLockResourceIDQuery(cls):
</ins><span class="cx">         meta = cls._homeMetaDataSchema
</span><span class="cx">         return Select(From=meta,
</span><span class="cx">                       Where=meta.RESOURCE_ID == Parameter(&quot;resourceID&quot;),
</span><span class="lines">@@ -2497,7 +2551,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _increaseQuotaQuery(cls): #@NoSelf
</del><ins>+    def _increaseQuotaQuery(cls):
</ins><span class="cx">         meta = cls._homeMetaDataSchema
</span><span class="cx">         return Update({meta.QUOTA_USED_BYTES: meta.QUOTA_USED_BYTES +
</span><span class="cx">                        Parameter(&quot;delta&quot;)},
</span><span class="lines">@@ -2506,7 +2560,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _resetQuotaQuery(cls): #@NoSelf
</del><ins>+    def _resetQuotaQuery(cls):
</ins><span class="cx">         meta = cls._homeMetaDataSchema
</span><span class="cx">         return Update({meta.QUOTA_USED_BYTES: 0},
</span><span class="cx">                       Where=meta.RESOURCE_ID == Parameter(&quot;resourceID&quot;))
</span><span class="lines">@@ -2517,8 +2571,8 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Adjust quota used. We need to get a lock on the row first so that the
</span><span class="cx">         adjustment is done atomically. It is import to do the 'select ... for
</span><del>-        update' because a race also exists in the 'update ... x = x + 1' case as
-        seen via unit tests.
</del><ins>+        update' because a race also exists in the 'update ... x = x + 1' case
+        as seen via unit tests.
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         yield self._preLockResourceIDQuery.on(self._txn,
</span><span class="cx">                                               resourceID=self._resourceID)
</span><span class="lines">@@ -2529,8 +2583,10 @@
</span><span class="cx">         # Double check integrity
</span><span class="cx">         if self._quotaUsedBytes &lt; 0:
</span><span class="cx">             log.error(
</span><del>-                &quot;Fixing quota adjusted below zero to %s by change amount %s&quot; %
-                (self._quotaUsedBytes, delta,))
</del><ins>+                &quot;Fixing quota adjusted below zero to {used} by change amount &quot;
+                &quot;{delta}&quot;,
+                used=self._quotaUsedBytes, delta=delta
+            )
</ins><span class="cx">             yield self._resetQuotaQuery.on(self._txn,
</span><span class="cx">                                            resourceID=self._resourceID)
</span><span class="cx">             self._quotaUsedBytes = 0
</span><span class="lines">@@ -2579,7 +2635,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _lockLastModifiedQuery(cls): #@NoSelf
</del><ins>+    def _lockLastModifiedQuery(cls):
</ins><span class="cx">         meta = cls._homeMetaDataSchema
</span><span class="cx">         return Select(
</span><span class="cx">             From=meta,
</span><span class="lines">@@ -2590,7 +2646,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _changeLastModifiedQuery(cls): #@NoSelf
</del><ins>+    def _changeLastModifiedQuery(cls):
</ins><span class="cx">         meta = cls._homeMetaDataSchema
</span><span class="cx">         return Update({meta.MODIFIED: utcNowSQL},
</span><span class="cx">                       Where=meta.RESOURCE_ID == Parameter(&quot;resourceID&quot;),
</span><span class="lines">@@ -2600,24 +2656,32 @@
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def bumpModified(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        Bump the MODIFIED value. A possible deadlock could happen here if two or more
-        simultaneous changes are happening. In that case it is OK for the MODIFIED change
-        to fail so long as at least one works. We will use SAVEPOINT logic to handle
-        ignoring the deadlock error. We use SELECT FOR UPDATE NOWAIT to ensure we do not
-        delay the transaction whilst waiting for deadlock detection to kick in.
</del><ins>+        Bump the MODIFIED value. A possible deadlock could happen here if two
+        or more simultaneous changes are happening. In that case it is OK for
+        the MODIFIED change to fail so long as at least one works. We will use
+        SAVEPOINT logic to handle ignoring the deadlock error. We use SELECT
+        FOR UPDATE NOWAIT to ensure we do not delay the transaction whilst
+        waiting for deadlock detection to kick in.
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-        # NB if modified is bumped we know that sync token will have changed too, so invalidate the cached value
</del><ins>+        # NB if modified is bumped we know that sync token will have changed
+        # too, so invalidate the cached value
</ins><span class="cx">         self._syncTokenRevision = None
</span><span class="cx"> 
</span><span class="cx">         @inlineCallbacks
</span><span class="cx">         def _bumpModified(subtxn):
</span><del>-            yield self._lockLastModifiedQuery.on(subtxn, resourceID=self._resourceID)
-            result = (yield self._changeLastModifiedQuery.on(subtxn, resourceID=self._resourceID))
</del><ins>+            yield self._lockLastModifiedQuery.on(
+                subtxn, resourceID=self._resourceID
+            )
+            result = yield self._changeLastModifiedQuery.on(
+                subtxn, resourceID=self._resourceID
+            )
</ins><span class="cx">             returnValue(result)
</span><span class="cx"> 
</span><span class="cx">         try:
</span><del>-            self._modified = (yield self._txn.subtransaction(_bumpModified, retries=0, failureOK=True))[0][0]
</del><ins>+            self._modified = (
+                yield self._txn.subtransaction(_bumpModified, retries=0, failureOK=True)
+            )[0][0]
</ins><span class="cx">             yield self.invalidateQueryCache()
</span><span class="cx"> 
</span><span class="cx">         except AllRetriesFailed:
</span><span class="lines">@@ -2657,7 +2721,7 @@
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _childSyncTokenQuery(cls): #@NoSelf
</del><ins>+    def _childSyncTokenQuery(cls):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL query for retrieving the sync token of a L{CommonHomeChild} based on
</span><span class="cx">         its resource ID.
</span><span class="lines">@@ -2692,7 +2756,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classmethod
</span><del>-    def _objectNamesSinceRevisionQuery(cls, deleted=True): #@NoSelf
</del><ins>+    def _objectNamesSinceRevisionQuery(cls, deleted=True):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL query for (resource, deleted-flag)
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -2756,7 +2820,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _removeDeletedRevision(cls): #@NoSelf
</del><ins>+    def _removeDeletedRevision(cls):
</ins><span class="cx">         rev = cls._revisionsSchema
</span><span class="cx">         return Delete(From=rev,
</span><span class="cx">                       Where=(rev.HOME_RESOURCE_ID == Parameter(&quot;homeID&quot;)).And(
</span><span class="lines">@@ -2764,7 +2828,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _addNewRevision(cls): #@NoSelf
</del><ins>+    def _addNewRevision(cls):
</ins><span class="cx">         rev = cls._revisionsSchema
</span><span class="cx">         return Insert({rev.HOME_RESOURCE_ID: Parameter(&quot;homeID&quot;),
</span><span class="cx">                        rev.RESOURCE_ID: Parameter(&quot;resourceID&quot;),
</span><span class="lines">@@ -2789,7 +2853,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _renameSyncTokenQuery(cls): #@NoSelf
</del><ins>+    def _renameSyncTokenQuery(cls):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL query to change sync token for a rename (increment and adjust
</span><span class="cx">         resource name).
</span><span class="lines">@@ -2814,7 +2878,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _bumpSyncTokenQuery(cls): #@NoSelf
</del><ins>+    def _bumpSyncTokenQuery(cls):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL query to change collection sync token. Note this can impact multiple rows if the
</span><span class="cx">         collection is shared.
</span><span class="lines">@@ -2840,7 +2904,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _deleteSyncTokenQuery(cls): #@NoSelf
</del><ins>+    def _deleteSyncTokenQuery(cls):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL query to update a sync revision to be a tombstone instead.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -2854,7 +2918,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _sharedRemovalQuery(cls): #@NoSelf
</del><ins>+    def _sharedRemovalQuery(cls):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL query to update the sync token for a shared collection.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -2869,7 +2933,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _unsharedRemovalQuery(cls): #@NoSelf
</del><ins>+    def _unsharedRemovalQuery(cls):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL query to update the sync token for an owned collection.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -2916,7 +2980,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _deleteBumpTokenQuery(cls): #@NoSelf
</del><ins>+    def _deleteBumpTokenQuery(cls):
</ins><span class="cx">         rev = cls._revisionsSchema
</span><span class="cx">         return Update({rev.REVISION: schema.REVISION_SEQ,
</span><span class="cx">                        rev.DELETED: True},
</span><span class="lines">@@ -2926,7 +2990,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _updateBumpTokenQuery(cls): #@NoSelf
</del><ins>+    def _updateBumpTokenQuery(cls):
</ins><span class="cx">         rev = cls._revisionsSchema
</span><span class="cx">         return Update({rev.REVISION: schema.REVISION_SEQ},
</span><span class="cx">                       Where=(rev.RESOURCE_ID == Parameter(&quot;resourceID&quot;)).And(
</span><span class="lines">@@ -2935,7 +2999,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _insertFindPreviouslyNamedQuery(cls): #@NoSelf
</del><ins>+    def _insertFindPreviouslyNamedQuery(cls):
</ins><span class="cx">         rev = cls._revisionsSchema
</span><span class="cx">         return Select([rev.RESOURCE_ID], From=rev,
</span><span class="cx">                       Where=(rev.RESOURCE_ID == Parameter(&quot;resourceID&quot;)).And(
</span><span class="lines">@@ -2943,7 +3007,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _updatePreviouslyNamedQuery(cls): #@NoSelf
</del><ins>+    def _updatePreviouslyNamedQuery(cls):
</ins><span class="cx">         rev = cls._revisionsSchema
</span><span class="cx">         return Update({rev.REVISION: schema.REVISION_SEQ,
</span><span class="cx">                        rev.DELETED: False},
</span><span class="lines">@@ -2953,7 +3017,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _completelyNewRevisionQuery(cls): #@NoSelf
</del><ins>+    def _completelyNewRevisionQuery(cls):
</ins><span class="cx">         rev = cls._revisionsSchema
</span><span class="cx">         return Insert({rev.HOME_RESOURCE_ID: Parameter(&quot;homeID&quot;),
</span><span class="cx">                        rev.RESOURCE_ID: Parameter(&quot;resourceID&quot;),
</span><span class="lines">@@ -3028,7 +3092,7 @@
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _bindInsertQuery(cls, **kw): #@NoSelf #@UnusedVariable
</del><ins>+    def _bindInsertQuery(cls, **kw):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL statement to create a bind entry that connects a collection to its
</span><span class="cx">         home.
</span><span class="lines">@@ -3046,7 +3110,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classmethod
</span><del>-    def _updateBindColumnsQuery(cls, columnMap): #@NoSelf
</del><ins>+    def _updateBindColumnsQuery(cls, columnMap):
</ins><span class="cx">         bind = cls._bindSchema
</span><span class="cx">         return Update(
</span><span class="cx">             columnMap,
</span><span class="lines">@@ -3056,7 +3120,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _deleteBindForResourceIDAndHomeID(cls): #@NoSelf
</del><ins>+    def _deleteBindForResourceIDAndHomeID(cls):
</ins><span class="cx">         bind = cls._bindSchema
</span><span class="cx">         return Delete(
</span><span class="cx">             From=bind,
</span><span class="lines">@@ -3066,7 +3130,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classmethod
</span><del>-    def _bindFor(cls, condition): #@NoSelf
</del><ins>+    def _bindFor(cls, condition):
</ins><span class="cx">         bind = cls._bindSchema
</span><span class="cx">         columns = cls.bindColumns() + cls.additionalBindColumns()
</span><span class="cx">         return Select(
</span><span class="lines">@@ -3077,7 +3141,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classmethod
</span><del>-    def _bindInviteFor(cls, condition): #@NoSelf
</del><ins>+    def _bindInviteFor(cls, condition):
</ins><span class="cx">         home = cls._homeSchema
</span><span class="cx">         bind = cls._bindSchema
</span><span class="cx">         return Select(
</span><span class="lines">@@ -3096,7 +3160,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _sharedInvitationBindForResourceID(cls): #@NoSelf
</del><ins>+    def _sharedInvitationBindForResourceID(cls):
</ins><span class="cx">         bind = cls._bindSchema
</span><span class="cx">         return cls._bindInviteFor(
</span><span class="cx">             (bind.RESOURCE_ID == Parameter(&quot;resourceID&quot;)).And
</span><span class="lines">@@ -3105,14 +3169,14 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _acceptedBindForHomeID(cls): #@NoSelf
</del><ins>+    def _acceptedBindForHomeID(cls):
</ins><span class="cx">         bind = cls._bindSchema
</span><span class="cx">         return cls._bindFor((bind.HOME_RESOURCE_ID == Parameter(&quot;homeID&quot;))
</span><span class="cx">                             .And(bind.BIND_STATUS == _BIND_STATUS_ACCEPTED))
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _bindForResourceIDAndHomeID(cls): #@NoSelf
</del><ins>+    def _bindForResourceIDAndHomeID(cls):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL query that looks up home bind rows by home child
</span><span class="cx">         resource ID and home resource ID.
</span><span class="lines">@@ -3123,7 +3187,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _bindForExternalIDAndHomeID(cls): #@NoSelf
</del><ins>+    def _bindForExternalIDAndHomeID(cls):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL query that looks up home bind rows by home child
</span><span class="cx">         resource ID and home resource ID.
</span><span class="lines">@@ -3134,7 +3198,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _bindForNameAndHomeID(cls): #@NoSelf
</del><ins>+    def _bindForNameAndHomeID(cls):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL query that looks up any bind rows by home child
</span><span class="cx">         resource ID and home resource ID.
</span><span class="lines">@@ -3951,7 +4015,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _childrenAndMetadataForHomeID(cls): #@NoSelf
</del><ins>+    def _childrenAndMetadataForHomeID(cls):
</ins><span class="cx">         bind = cls._bindSchema
</span><span class="cx">         child = cls._homeChildSchema
</span><span class="cx">         childMetaData = cls._homeChildMetaDataSchema
</span><span class="lines">@@ -4299,7 +4363,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _insertHomeChild(cls): #@NoSelf
</del><ins>+    def _insertHomeChild(cls):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL statement to create a home child with all default values.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -4311,7 +4375,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _insertHomeChildMetaData(cls): #@NoSelf
</del><ins>+    def _insertHomeChildMetaData(cls):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL statement to create a home child with all default values.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -4354,7 +4418,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _metadataByIDQuery(cls): #@NoSelf
</del><ins>+    def _metadataByIDQuery(cls):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL query to retrieve created/modified dates based on a resource ID.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -4417,7 +4481,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _renameQuery(cls): #@NoSelf
</del><ins>+    def _renameQuery(cls):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL statement to rename a L{CommonHomeChild}
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -4457,7 +4521,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _deleteQuery(cls): #@NoSelf
</del><ins>+    def _deleteQuery(cls):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL statement to delete a L{CommonHomeChild} by its resource ID.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -4506,7 +4570,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _ownerHomeWithResourceID(cls): #@NoSelf
</del><ins>+    def _ownerHomeWithResourceID(cls):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL query to retrieve the home resource ID and resource name of the owner from the bound
</span><span class="cx">         home-child ID.
</span><span class="lines">@@ -4549,7 +4613,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _objectResourceNamesQuery(cls): #@NoSelf
</del><ins>+    def _objectResourceNamesQuery(cls):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL query to load all object resource names for a home child.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -4568,7 +4632,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _objectCountQuery(cls): #@NoSelf
</del><ins>+    def _objectCountQuery(cls):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL query to count all object resources for a home child.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -4628,7 +4692,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _resourceNameForUIDQuery(cls): #@NoSelf
</del><ins>+    def _resourceNameForUIDQuery(cls):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL query to retrieve the resource name for an object resource based on
</span><span class="cx">         its UID column.
</span><span class="lines">@@ -4657,7 +4721,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _resourceUIDForNameQuery(cls): #@NoSelf
</del><ins>+    def _resourceUIDForNameQuery(cls):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL query to retrieve the UID for an object resource based on its
</span><span class="cx">         resource name column.
</span><span class="lines">@@ -4727,7 +4791,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _moveParentUpdateQuery(cls, adjustName=False): #@NoSelf
</del><ins>+    def _moveParentUpdateQuery(cls, adjustName=False):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL query to update a child to be in a new parent.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -5127,7 +5191,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _lockLastModifiedQuery(cls): #@NoSelf
</del><ins>+    def _lockLastModifiedQuery(cls):
</ins><span class="cx">         schema = cls._homeChildMetaDataSchema
</span><span class="cx">         return Select(
</span><span class="cx">             From=schema,
</span><span class="lines">@@ -5138,7 +5202,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _changeLastModifiedQuery(cls): #@NoSelf
</del><ins>+    def _changeLastModifiedQuery(cls):
</ins><span class="cx">         schema = cls._homeChildMetaDataSchema
</span><span class="cx">         return Update({schema.MODIFIED: utcNowSQL},
</span><span class="cx">                       Where=schema.RESOURCE_ID == Parameter(&quot;resourceID&quot;),
</span><span class="lines">@@ -5148,25 +5212,36 @@
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def bumpModified(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        Bump the MODIFIED value. A possible deadlock could happen here if two or more
-        simultaneous changes are happening. In that case it is OK for the MODIFIED change
-        to fail so long as at least one works. We will use SAVEPOINT logic to handle
-        ignoring the deadlock error. We use SELECT FOR UPDATE NOWAIT to ensure we do not
-        delay the transaction whilst waiting for deadlock detection to kick in.
</del><ins>+        Bump the MODIFIED value. A possible deadlock could happen here if two
+        or more simultaneous changes are happening. In that case it is OK for
+        the MODIFIED change to fail so long as at least one works. We will use
+        SAVEPOINT logic to handle ignoring the deadlock error. We use SELECT
+        FOR UPDATE NOWAIT to ensure we do not delay the transaction whilst
+        waiting for deadlock detection to kick in.
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         @inlineCallbacks
</span><span class="cx">         def _bumpModified(subtxn):
</span><del>-            yield self._lockLastModifiedQuery.on(subtxn, resourceID=self._resourceID)
-            result = (yield self._changeLastModifiedQuery.on(subtxn, resourceID=self._resourceID))
</del><ins>+            yield self._lockLastModifiedQuery.on(
+                subtxn, resourceID=self._resourceID
+            )
+            result = yield self._changeLastModifiedQuery.on(
+                subtxn, resourceID=self._resourceID
+            )
</ins><span class="cx">             returnValue(result)
</span><span class="cx"> 
</span><span class="cx">         try:
</span><del>-            self._modified = (yield self._txn.subtransaction(_bumpModified, retries=0, failureOK=True))[0][0]
</del><ins>+            self._modified = (
+                yield self._txn.subtransaction(
+                    _bumpModified, retries=0, failureOK=True
+                )
+            )[0][0]
</ins><span class="cx"> 
</span><span class="cx">             queryCacher = self._txn._queryCacher
</span><span class="cx">             if queryCacher is not None:
</span><del>-                cacheKey = queryCacher.keyForHomeChildMetaData(self._resourceID)
</del><ins>+                cacheKey = queryCacher.keyForHomeChildMetaData(
+                    self._resourceID
+                )
</ins><span class="cx">                 yield queryCacher.invalidateAfterCommit(self._txn, cacheKey)
</span><span class="cx">         except AllRetriesFailed:
</span><span class="cx">             log.debug(&quot;CommonHomeChild.bumpModified failed&quot;)
</span><span class="lines">@@ -5199,9 +5274,12 @@
</span><span class="cx"> 
</span><span class="cx">         @param parent: the parent collection object
</span><span class="cx">         @type parent: L{CommonHomeChild}
</span><ins>+
</ins><span class="cx">         @param objectData: the standard set of object columns
</span><span class="cx">         @type objectData: C{list}
</span><del>-        @param propstore: a property store to use, or C{None} to load it automatically
</del><ins>+
+        @param propstore: a property store to use, or C{None} to load it
+            automatically
</ins><span class="cx">         @type propstore: L{PropertyStore}
</span><span class="cx"> 
</span><span class="cx">         @return: the constructed child class
</span><span class="lines">@@ -5279,7 +5357,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _allColumnsWithParentQuery(cls): #@NoSelf
</del><ins>+    def _allColumnsWithParentQuery(cls):
</ins><span class="cx">         obj = cls._objectSchema
</span><span class="cx">         return Select(cls._allColumns(), From=obj,
</span><span class="cx">                       Where=obj.PARENT_RESOURCE_ID == Parameter(&quot;parentID&quot;))
</span><span class="lines">@@ -5485,22 +5563,22 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _allColumnsWithParentAndName(cls): #@NoSelf
</del><ins>+    def _allColumnsWithParentAndName(cls):
</ins><span class="cx">         return cls._allColumnsWithParentAnd(cls._objectSchema.RESOURCE_NAME, &quot;name&quot;)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _allColumnsWithParentAndUID(cls): #@NoSelf
</del><ins>+    def _allColumnsWithParentAndUID(cls):
</ins><span class="cx">         return cls._allColumnsWithParentAnd(cls._objectSchema.UID, &quot;uid&quot;)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _allColumnsWithParentAndID(cls): #@NoSelf
</del><ins>+    def _allColumnsWithParentAndID(cls):
</ins><span class="cx">         return cls._allColumnsWithParentAnd(cls._objectSchema.RESOURCE_ID, &quot;resourceID&quot;)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classmethod
</span><del>-    def _allColumns(cls): #@NoSelf
</del><ins>+    def _allColumns(cls):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Full set of columns in the object table that need to be loaded to
</span><span class="cx">         initialize the object resource state.
</span><span class="lines">@@ -5518,7 +5596,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classmethod
</span><del>-    def _rowAttributes(cls): #@NoSelf
</del><ins>+    def _rowAttributes(cls):
</ins><span class="cx">         return (
</span><span class="cx">             &quot;_resourceID&quot;,
</span><span class="cx">             &quot;_name&quot;,
</span><span class="lines">@@ -5531,7 +5609,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classmethod
</span><del>-    def _otherSerializedAttributes(cls): #@NoSelf
</del><ins>+    def _otherSerializedAttributes(cls):
</ins><span class="cx">         return (
</span><span class="cx">             &quot;_componentChanged&quot;,
</span><span class="cx">         )
</span><span class="lines">@@ -5642,7 +5720,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classmethod
</span><del>-    def _selectForUpdateQuery(cls, nowait): #@NoSelf
</del><ins>+    def _selectForUpdateQuery(cls, nowait):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL statement to lock a L{CommonObjectResource} by its resource ID.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -5686,7 +5764,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _deleteQuery(cls): #@NoSelf
</del><ins>+    def _deleteQuery(cls):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL statement to delete a L{CommonObjectResource} by its resource ID.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -5780,7 +5858,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _textByIDQuery(cls): #@NoSelf
</del><ins>+    def _textByIDQuery(cls):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL query to load iCalendar/vCard text via an object's resource ID.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -5949,7 +6027,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _dataVersionQuery(cls): #@NoSelf
</del><ins>+    def _dataVersionQuery(cls):
</ins><span class="cx">         nh = cls._homeSchema
</span><span class="cx">         return Select(
</span><span class="cx">             [nh.DATAVERSION], From=nh,
</span><span class="lines">@@ -6156,7 +6234,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _completelyNewRevisionQuery(cls): #@NoSelf
</del><ins>+    def _completelyNewRevisionQuery(cls):
</ins><span class="cx">         rev = cls._revisionsSchema
</span><span class="cx">         return Insert({rev.HOME_RESOURCE_ID: Parameter(&quot;homeID&quot;),
</span><span class="cx">                        # rev.RESOURCE_ID: Parameter(&quot;resourceID&quot;),
</span><span class="lines">@@ -6233,7 +6311,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _allColumnsByHomeIDQuery(cls): #@NoSelf
</del><ins>+    def _allColumnsByHomeIDQuery(cls):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL query to load all columns by home ID.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -6298,7 +6376,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _oneNotificationQuery(cls): #@NoSelf
</del><ins>+    def _oneNotificationQuery(cls):
</ins><span class="cx">         no = cls._objectSchema
</span><span class="cx">         return Select(
</span><span class="cx">             [
</span><span class="lines">@@ -6383,7 +6461,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _newNotificationQuery(cls): #@NoSelf
</del><ins>+    def _newNotificationQuery(cls):
</ins><span class="cx">         no = cls._objectSchema
</span><span class="cx">         return Insert(
</span><span class="cx">             {
</span><span class="lines">@@ -6398,7 +6476,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _updateNotificationQuery(cls): #@NoSelf
</del><ins>+    def _updateNotificationQuery(cls):
</ins><span class="cx">         no = cls._objectSchema
</span><span class="cx">         return Update(
</span><span class="cx">             {
</span><span class="lines">@@ -6657,8 +6735,8 @@
</span><span class="cx">         else:
</span><span class="cx">             estimate = &quot;unknown&quot;
</span><span class="cx">         log.info(
</span><del>-            format=&quot;Scanning UID %(uid)s [%(homeType)s] &quot;
-            &quot;(%(pct)0.2d%%, %(estimate)s seconds remaining)...&quot;,
</del><ins>+            &quot;Scanning UID {uid} [{homeType}] &quot;
+            &quot;({pct!0.2d}%, {estimate} seconds remaining)...&quot;,
</ins><span class="cx">             uid=UID, pct=(n / float(total)) * 100, estimate=estimate,
</span><span class="cx">             homeType=homeTypeName
</span><span class="cx">         )
</span><span class="lines">@@ -6670,8 +6748,9 @@
</span><span class="cx">             fixedThisHome = 0
</span><span class="cx">         fixedOtherHome = 0
</span><span class="cx">         if this is None:
</span><del>-            log.info(format=&quot;%(uid)r appears to be missing, already processed&quot;,
-                     uid=UID)
</del><ins>+            log.info(
+                &quot;{uid!r} appears to be missing, already processed&quot;, uid=UID
+            )
</ins><span class="cx">         try:
</span><span class="cx">             uuidobj = UUID(UID)
</span><span class="cx">         except ValueError:
</span><span class="lines">@@ -6679,9 +6758,10 @@
</span><span class="cx">         else:
</span><span class="cx">             newname = str(uuidobj).upper()
</span><span class="cx">             if UID != newname:
</span><del>-                log.info(format=&quot;Detected case variance: %(uid)s %(newuid)s&quot;
-                         &quot;[%(homeType)s]&quot;,
-                         uid=UID, newuid=newname, homeType=homeTypeName)
</del><ins>+                log.info(
+                    &quot;Detected case variance: {uid} {newuid}[{homeType}]&quot;,
+                    uid=UID, newuid=newname, homeType=homeTypeName
+                )
</ins><span class="cx">                 other = yield _getHome(t, homeType, newname)
</span><span class="cx">                 if other is None:
</span><span class="cx">                     # No duplicate: just fix the name.
</span><span class="lines">@@ -6696,10 +6776,12 @@
</span><span class="cx">         end = time.time()
</span><span class="cx">         elapsed = end - start
</span><span class="cx">         allElapsed.append(elapsed)
</span><del>-        log.info(format=&quot;Scanned UID %(uid)s; %(elapsed)s seconds elapsed,&quot;
-                 &quot; %(fixes)s properties fixed (%(duplicate)s fixes in &quot;
-                 &quot;duplicate).&quot;, uid=UID, elapsed=elapsed, fixes=fixedThisHome,
-                 duplicate=fixedOtherHome)
</del><ins>+        log.info(
+            &quot;Scanned UID {uid}; {elapsed} seconds elapsed,&quot;
+            &quot; {fixes} properties fixed ({duplicate} fixes in duplicate).&quot;,
+            uid=UID, elapsed=elapsed, fixes=fixedThisHome,
+            duplicate=fixedOtherHome
+        )
</ins><span class="cx">     returnValue(None)
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>