Skip to content

Commit

Permalink
On removal of site remove the sub of its site manager from parent sit…
Browse files Browse the repository at this point in the history
…e manager (#14)

Fixes #1.

The implementation was originally taken from https://github.com/zopefoundation/grokcore.site/blob/fc945c90c5093de8f7ff958cf498eb6305b9c068/src/grokcore/site/subscriber.py#L35-L46 but changed in the review process of this PR.

Co-authored-by: Jason Madden <jamadden@gmail.com>
  • Loading branch information
Michael Howitz and jamadden committed Sep 10, 2020
1 parent e7c56a9 commit 2e2411d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
6 changes: 4 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
Changes
=========

4.3.1 (unreleased)
4.4.0 (unreleased)
==================

- Nothing changed yet.
- On removal of a site, clear the bases of its site manager. This fixes a reference leak
from a parent site manager. See
`issue 1 <https://github.com/zopefoundation/zope.site/issues/1>`_.


4.3.0 (2020-04-01)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def read(*rnames):
]

setup(name='zope.site',
version='4.3.1.dev0',
version='4.4.0.dev0',
author='Zope Foundation and Contributors',
author_email='zope-dev@zope.org',
description='Local registries for zope component architecture',
Expand Down
7 changes: 5 additions & 2 deletions src/zope/site/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,16 +242,19 @@ def SiteManagerAdapter(ob):

def changeSiteConfigurationAfterMove(site, event):
"""
After a site is moved, its site manager links have to be
After a site is (re-)moved, its site manager links have to be
updated.
Subscriber to :class:`~.ISite` objects in a :class:`~.IObjectMovedEvent`.
"""
local_sm = site.getSiteManager()
if event.newParent is not None:
next = _findNextSiteManager(site)
if next is None:
next = zope.component.getGlobalSiteManager()
site.getSiteManager().__bases__ = (next, )
local_sm.__bases__ = (next, )
else:
local_sm.__bases__ = ()


@zope.component.adapter(
Expand Down
13 changes: 12 additions & 1 deletion src/zope/site/site.rst
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ site hierarchy is as follows:

_____ global site _____
/ \
myfolder1 myfolder2
myfolder myfolder2
|
myfolder11

Expand Down Expand Up @@ -352,3 +352,14 @@ sitemanager's bases should be set to global site manager.
>>> nosm['root'] = myfolder11
>>> myfolder11.getSiteManager().__bases__ == (gsm, )
True

Deleting a site unregisters its site manger from its parent site manager:

>>> del myfolder2['myfolder21']
>>> myfolder2.getSiteManager().subs
()

The removed site manager now has no bases:

>>> myfolder21.getSiteManager().__bases__
()

0 comments on commit 2e2411d

Please sign in to comment.