From 51eee8ec8fd8276f3e92c1e5ae4a3e9995ccce55 2020-11-04 18:43:54 From: Brett Smith Date: 2020-11-04 18:43:54 Subject: [PATCH] meta_entity: Don't set transaction metadata when payee is None. RT#12913 --- diff --git a/conservancy_beancount/plugin/meta_entity.py b/conservancy_beancount/plugin/meta_entity.py index a105b0be4396fee8db20f4d7edaca9ceb868752a..868183fdcb3787081c14f5a8d1e4f0dae9c27af7 100644 --- a/conservancy_beancount/plugin/meta_entity.py +++ b/conservancy_beancount/plugin/meta_entity.py @@ -72,7 +72,7 @@ class MetaEntity(core.TransactionHook): txn_entity, txn_entity_ok = self._check_entity(txn.meta, txn.payee) if txn_entity_ok is False: yield errormod.InvalidMetadataError(txn, self.METADATA_KEY, txn_entity) - if txn_entity is txn.payee: + if txn_entity is txn.payee and txn_entity is not None: txn.meta[self.METADATA_KEY] = txn.payee for post in data.Posting.from_txn(txn): if not post.account.is_under( diff --git a/setup.py b/setup.py index 19f9f9ce2ce6cb08a71819d71b8fc530df2b9859..f61c40635297cf6d2cc29dd41bc74dd3d967613c 100755 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ from setuptools import setup setup( name='conservancy_beancount', description="Plugin, library, and reports for reading Conservancy's books", - version='1.13.0', + version='1.13.1', author='Software Freedom Conservancy', author_email='info@sfconservancy.org', license='GNU AGPLv3+', diff --git a/tests/test_meta_entity.py b/tests/test_meta_entity.py index dd5c7121745c32db08c9490edabd9c1d9beb42bd..f8b012238e5c8e0ac8404c8df1e46fc693f24a59 100644 --- a/tests/test_meta_entity.py +++ b/tests/test_meta_entity.py @@ -214,6 +214,16 @@ def test_which_accounts_required_on(hook, account, required): assert any(error.message == "{} missing entity".format(account) for error in errors) +def test_dont_set_entity_none(hook): + txn = testutil.Transaction(postings=[ + ('Expenses:Other', 5), + ('Assets:Cash', -5), + ]) + assert any(hook.run(txn)) + assert 'entity' not in txn.meta + for post in txn.postings: + assert post.meta is None or 'entity' not in post.meta + def test_not_required_on_opening(hook): txn = testutil.OpeningBalance() assert not list(hook.run(txn))