From 592faa16d38a473bb1f64a2515cb9d740ea3692c Mon Sep 17 00:00:00 2001 From: Tom Keffer Date: Mon, 20 Feb 2023 17:34:00 -0800 Subject: [PATCH] Catch UnknownBinding exception. Using a bad data binding with an aggregation tag no longer results in an exception. Instead, it shows the tag in the results. This parallels behavior with a $current tag. Related to PR #817. --- bin/weewx/tags.py | 7 ++++++- bin/weewx/tests/expected/StandardTest/index.html | 4 ++++ bin/weewx/tests/expected/StandardTest/metric/index.html | 4 ++++ bin/weewx/tests/test_skins/StandardTest/index.html.tmpl | 4 ++++ docs/changes.txt | 3 +++ 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/bin/weewx/tags.py b/bin/weewx/tags.py index cdc8385a..57812196 100644 --- a/bin/weewx/tags.py +++ b/bin/weewx/tags.py @@ -482,7 +482,12 @@ class AggTypeBinder(object): def _do_query(self): """Run a query against the databases, using the given aggregation type.""" - db_manager = self.db_lookup(self.data_binding) + try: + # Get the appropriate database manager + db_manager = self.db_lookup(self.data_binding) + except weewx.UnknownBinding: + # Don't recognize the binding. + raise AttributeError(self.data_binding) try: # If we cannot perform the aggregation, we will get an UnknownType or # UnknownAggregation error. Be prepared to catch it. diff --git a/bin/weewx/tests/expected/StandardTest/index.html b/bin/weewx/tests/expected/StandardTest/index.html index ddb1cb37..a8be0523 100644 --- a/bin/weewx/tests/expected/StandardTest/index.html +++ b/bin/weewx/tests/expected/StandardTest/index.html @@ -506,6 +506,10 @@ Max Temperature in alt_binding 25.1°F + + Max Temperature with bogus binding + $day($data_binding='foo_binding').outTemp.max + Min temp with explicit conversion to Celsius 3.8°C diff --git a/bin/weewx/tests/expected/StandardTest/metric/index.html b/bin/weewx/tests/expected/StandardTest/metric/index.html index f523580f..a01798aa 100644 --- a/bin/weewx/tests/expected/StandardTest/metric/index.html +++ b/bin/weewx/tests/expected/StandardTest/metric/index.html @@ -506,6 +506,10 @@ Max Temperature in alt_binding -3.9°C + + Max Temperature with bogus binding + $day($data_binding='foo_binding').outTemp.max + Min temp with explicit conversion to Celsius 3.8°C diff --git a/bin/weewx/tests/test_skins/StandardTest/index.html.tmpl b/bin/weewx/tests/test_skins/StandardTest/index.html.tmpl index ea01caf3..8309bc11 100644 --- a/bin/weewx/tests/test_skins/StandardTest/index.html.tmpl +++ b/bin/weewx/tests/test_skins/StandardTest/index.html.tmpl @@ -506,6 +506,10 @@ FALSE#slurp Max Temperature in alt_binding $day($data_binding='alt_binding').outTemp.max + + Max Temperature with bogus binding + $day($data_binding='foo_binding').outTemp.max + Min temp with explicit conversion to Celsius $day.outTemp.min.degree_C diff --git a/docs/changes.txt b/docs/changes.txt index 7c37fe8b..75ca29df 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -17,6 +17,9 @@ user jocelynj! PR #842. Fix problem that prevented wee_device --set-retransmit from working on Vantage stations. +Using a bad data binding with an aggregation tag no longer results in an +exception. Instead, it shows the tag in the results. Related to PR #817. + 4.10.1 01/30/2023