diff --git a/beetsplug/inline.py b/beetsplug/inline.py index fd0e9fc30..bf6ff92da 100644 --- a/beetsplug/inline.py +++ b/beetsplug/inline.py @@ -117,9 +117,13 @@ class InlinePlugin(BeetsPlugin): # For function bodies, invoke the function with values as global # variables. def _func_func(obj): + old_globals = dict(func.__globals__) func.__globals__.update(_dict_for(obj)) try: return func() except Exception as exc: raise InlineError(python_code, exc) + finally: + func.__globals__.clear() + func.__globals__.update(old_globals) return _func_func diff --git a/docs/changelog.rst b/docs/changelog.rst index 371acb8c8..7a74f556b 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -12,6 +12,15 @@ New features: Thanks to :user:`dosoe`. :bug:`2580` :bug:`3272` +Fixes: + +* :doc:`/plugins/inline`: In function-style field definitions that refer to + flexible attributes, values could stick around from one function invocation + to the next. This meant that, when displaying a list of objects, later + objects could seem to reuse values from earlier objects when they were + missing a value for a given field. These values are now properly undefined. + :bug:`2406` + For plugin developers: * `MediaFile`_ has been split into a standalone project. Where you used to do