diff options
author | Matt Riedemann <mriedem@us.ibm.com> | 2014-08-29 02:10:41 -0700 |
---|---|---|
committer | Matt Riedemann <mriedem@us.ibm.com> | 2014-09-03 13:39:06 -0700 |
commit | 4d61c826eff57e112417e948f7166e8b29425f4a (patch) | |
tree | a4e9e51508045829d52f1c179aec7e9b6660a6a6 | |
parent | 5595911d10544a0358ce48eb06102505eb073528 (diff) | |
download | oslo-serialization-4d61c826eff57e112417e948f7166e8b29425f4a.tar.gz |
Check for namedtuple_as_object support before using it0.2.0
Commit ad248f6658d572f3f4721f804325db754e9c931d introduced the usage of
the namedtuple_as_object kwarg if using simplejson.
However, that kwarg isn't available until simplejson 2.2.0 which is a
problem for anyone running a RHEL/CentOS 6 distribution.
Normally this would not be a big deal since we can bump minimum required
versions but in this case simplejson is an optional runtime dependency
so most projects don't list it in their requirements.txt files. So if
you are running with simplejson < 2.2.0 (you might not even know it) and
upgrade, things are going to get sad very quick.
Rather than assume people will be at the right level or figure it out,
let's be smarter and just check if the kwarg is available in the version
of simplejson we're using. If we don't have a new enough version of
simplejson then fallback to using json despite the performance issues
on python 2.6.
This can be removed in Kilo when python 2.6 support is dropped so this
should be short-term workaround that saves some headaches once Juno is
released.
Closes-Bug: #1361230
Change-Id: Iadc2d28a1a0b125a34ed08344673c6b4a8a758e9
-rw-r--r-- | oslo/serialization/jsonutils.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/oslo/serialization/jsonutils.py b/oslo/serialization/jsonutils.py index 1edd76d..a14b827 100644 --- a/oslo/serialization/jsonutils.py +++ b/oslo/serialization/jsonutils.py @@ -44,7 +44,13 @@ if sys.version_info < (2, 7): # simplejson module if available try: import simplejson as json - is_simplejson = True + # NOTE(mriedem): Make sure we have a new enough version of simplejson + # to support the namedobject_as_tuple argument. This can be removed + # in the Kilo release when python 2.6 support is dropped. + if 'namedtuple_as_object' in inspect.getargspec(json.dumps).args: + is_simplejson = True + else: + import json except ImportError: import json else: |