Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

Comments

@quiver
Copy link
Contributor

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
Copy link
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
Copy link
Contributor Author

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
Copy link
Member

jamesls commented Feb 10, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants