Skip to content

when JSON config file is specified, null is converted to string 'None' #637

Closed
quiver opened this Issue Feb 7, 2014 · 3 comments

2 participants

@quiver
quiver commented Feb 7, 2014

When you set entire s3 bucket lifesycle, you get setting like follows:

$ aws s3api get-bucket-lifecycle --bucket my-bucket-name
{
    "Rules": [
        {
            "Status": "Enabled",
            "Prefix": null,
            "Transition": {
                "Days": 1,
                "StorageClass": "GLACIER"
            },
            "Expiration": {
                "Days": 5
            },
            "ID": "Rule for the Entire Bucket"
        }
    ]
}

note that "Prefix": null,
when I put this back lifesycle setting with this json, Prefix is set to string None.

$ aws s3api put-bucket-lifecycle --bucket my-bucket-name --lifecycle file://lifecycle.json
$ aws s3api get-bucket-lifecycle --bucket my-bucket-name
{
    "Rules": [
        {
            "Status": "Enabled",
            "Prefix": "None",
            "Transition": {
                "Days": 1,
                "StorageClass": "GLACIER"
            },
            "Expiration": {
                "Days": 5
            },
            "ID": "Rule for the Entire Bucket"
        }
    ]
}

Simple fix is adding None condition check when converting to xml.
If this approach is fine, I'll add a test case for that and pull request it.

$ git diff .
diff --git a/botocore/parameters.py b/botocore/parameters.py
index 8ad9cbd..4d78fe5 100644
--- a/botocore/parameters.py
+++ b/botocore/parameters.py
@@ -123,8 +123,10 @@ class Parameter(BotoCoreObject):
     def to_xml(self, value, label=None):
         if not label:
             label = self.name
-        return '<%s>%s</%s>' % (label, value, label)
-
+        if value is None:
+            return '<%s></%s>' % (label, label)
+        else:
+            return '<%s>%s</%s>' % (label, value, label)

 class IntegerParameter(Parameter):
@jamesls
Amazon Web Services member
jamesls commented Feb 8, 2014

I think this is a reasonable approach, feel free to send a PR with tests to the botocore repo.

You should be able to add the test in tests/unit/test_s3_operations.py

Thanks!

@quiver quiver referenced this issue in boto/botocore Feb 9, 2014
Merged

fix json -> xml request payload conversion #229

@quiver
quiver commented Feb 9, 2014

Thank for your feedback.
The code change is in botocore library, so I pull-requested to boto/botocore.

boto/botocore#229

@jamesls
Amazon Web Services member
jamesls commented Feb 10, 2014

boto/botocore#229 has now been merged. Thanks for the pull request.

@jamesls jamesls closed this Feb 10, 2014
@jamesls jamesls added a commit that referenced this issue Feb 10, 2014
@jamesls jamesls Update changelog with #637 bb8b570
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.