From c097af20ad430e7eb179a24f2d731e59f65784f6 Mon Sep 17 00:00:00 2001 From: Travis Redman Date: Mon, 13 May 2019 10:26:48 -0700 Subject: [PATCH] [middleware] support dict parameters type in flask middleware Fixes https://github.com/honeycombio/beeline-python/issues/62. Bumps version to 2.5.1 --- CHANGELOG.md | 7 +++++++ beeline/middleware/flask/__init__.py | 18 ++++++++++++++---- beeline/version.py | 2 +- setup.py | 2 +- 4 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..5343af5 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,7 @@ +# beeline-python changelog + +## 2.5.1 2019-05-13 + +Fixes + +- Support parameters of type `dict` in the flask-sqlachemy middleware. Addresses [#62](https://github.com/honeycombio/beeline-python/issues/62). \ No newline at end of file diff --git a/beeline/middleware/flask/__init__.py b/beeline/middleware/flask/__init__.py index 86d5479..e96a0bf 100644 --- a/beeline/middleware/flask/__init__.py +++ b/beeline/middleware/flask/__init__.py @@ -112,10 +112,20 @@ def before_cursor_execute(self, conn, cursor, statement, parameters, context, ex return params = [] - for param in parameters: - if type(param) == datetime.datetime: - param = param.isoformat() - params.append(param) + + # the type of parameters passed in varies depending on DB - handle list, dict, and tuple + if type(parameters) == tuple or type(parameters) == list: + for param in parameters: + if type(param) == datetime.datetime: + param = param.isoformat() + params.append(param) + elif type(parameters) == dict: + for k,v in parameters.items(): + param = "%s=" % k + if type(v) == datetime.datetime: + v = v.isoformat() + param += "%s" % v + params.append(param) self.state.span = beeline.start_span(context={ "name": "flask_db_query", diff --git a/beeline/version.py b/beeline/version.py index 8af1c58..d10c867 100644 --- a/beeline/version.py +++ b/beeline/version.py @@ -1 +1 @@ -VERSION = '2.5.0' +VERSION = '2.5.1' diff --git a/setup.py b/setup.py index 005198d..10d3191 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ setup( python_requires='>=2.7', name='honeycomb-beeline', - version='2.5.0', + version='2.5.1', description='Honeycomb library for easy instrumentation', url='https://github.com/honeycombio/beeline-python', author='Honeycomb.io',