From 00e32fc7d2ba1e256b59dadd6774332e04acdaa7 Mon Sep 17 00:00:00 2001 From: Hong Minhee Date: Sun, 18 Feb 2018 20:36:11 +0900 Subject: [PATCH 1/3] Version bump --- CHANGES.md | 6 ++++++ README.md | 2 +- docs/tutorial.md | 2 +- package.yaml | 2 +- test/Nirum/VersionSpec.hs | 2 +- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 690c560..c4d78b8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,12 @@ Nirum changelog =============== +Version 0.3.1 +------------- + +To be released. + + Version 0.3.0 ------------- diff --git a/README.md b/README.md index 84563d5..b172252 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ For more infomration, use `--help` option: Nirum: The IDL compiler and RPC/distributed object framework Usage: nirum [-v|--version] (-o|--output-dir DIR) (-t|--target TARGET) DIR - Nirum compiler 0.3.0 + Nirum compiler 0.3.1 Available options: -h,--help Show this help text diff --git a/docs/tutorial.md b/docs/tutorial.md index 8367aca..6e503e1 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -135,7 +135,7 @@ a command-line prompt and it's consistent within this tutorial): ~~~~~~~~ sh $ nirum -v -0.3.0 +0.3.1 ~~~~~~~~ [official releases page]: https://github.com/spoqa/nirum/releases diff --git a/package.yaml b/package.yaml index 33f1cd2..0f7c1fa 100644 --- a/package.yaml +++ b/package.yaml @@ -2,7 +2,7 @@ name: nirum version: # CHECK: When the version is bumped, update the docs and README.md file as # well. Check using `git grep -E '[0-9]+\.[0-9]+\.[0-9]+' '*.md'` command. - '0.3.0' + '0.3.1' synopsis: ! > IDL compiler and RPC/distributed object framework for microservices diff --git a/test/Nirum/VersionSpec.hs b/test/Nirum/VersionSpec.hs index 8d8e7b7..7d35481 100644 --- a/test/Nirum/VersionSpec.hs +++ b/test/Nirum/VersionSpec.hs @@ -17,7 +17,7 @@ spec = do version `shouldSatisfy` SV.isDevelopment it "is the proper version" $ -- is it a necessary test? - version `shouldBe` SV.version 0 3 0 [] [] + version `shouldBe` SV.version 0 3 1 [] [] describe "versionText" $ do it "is equivalent to version" $ versionText `shouldBe` SV.toText version From eaf85c3188d8a7b42c90559fbbba4d9ee2ec6b3d Mon Sep 17 00:00:00 2001 From: Hong Minhee Date: Wed, 21 Feb 2018 13:08:15 +0900 Subject: [PATCH 2/3] Make record/union deserializers ignore unknown fields (#238) Fix https://github.com/spoqa/nirum/issues/232 --- CHANGES.md | 8 +++++++- docs/refactoring.md | 9 +++++++++ docs/serialization.md | 7 +++++++ src/Nirum/Targets/Python.hs | 12 ++++++++++-- test/python/primitive_test.py | 28 ++++++++++++++++++++++------ 5 files changed, 55 insertions(+), 9 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c4d78b8..f26fe20 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,13 @@ Version 0.3.1 To be released. +### Python target + + - Fixed record/union deserializers to ignore unknown fields in data payload. + Deserializers had raised `KeyError` before. [#232] + +[#232]: https://github.com/spoqa/nirum/issues/232 + Version 0.3.0 ------------- @@ -172,7 +179,6 @@ Released on February 18, 2018. [#203]: https://github.com/spoqa/nirum/pull/203 [#204]: https://github.com/spoqa/nirum/pull/204 [#216]: https://github.com/spoqa/nirum/issues/216 -[#222]: https://github.com/spoqa/nirum/pull/222 [#218]: https://github.com/spoqa/nirum/issues/218 [#222]: https://github.com/spoqa/nirum/pull/222 [#223]: https://github.com/spoqa/nirum/pull/223 diff --git a/docs/refactoring.md b/docs/refactoring.md index 7ab6e23..2f167b6 100644 --- a/docs/refactoring.md +++ b/docs/refactoring.md @@ -129,6 +129,15 @@ returns, but in program codes we become able to deal with distance using `meter` type rather than primitive `bigint` type. +Removing a field +---------------- + +Any fields in payload that are unlisted in an interface definition are ignored +by a deserializer. If you are going to remove an existing field you should +deploy the newer version to a payload consumer first, and then a payload +provider last. + + Interchangeability of enum type and `text` ------------------------------------------ diff --git a/docs/serialization.md b/docs/serialization.md index 9bf5f17..3652f6c 100644 --- a/docs/serialization.md +++ b/docs/serialization.md @@ -201,6 +201,10 @@ It's represented in JSON to: "uri": null } +When a payload is deserialized, undefined fields are just ignored. +It can be used to drop an existing field without breaking +backward compatibility. + Union type ---------- @@ -243,6 +247,9 @@ It's represented in JSON to: "uri": null } +In a similar way to a recrod type, undefined fields in a payload are ignored +by deserializer. + Option type ----------- diff --git a/src/Nirum/Targets/Python.hs b/src/Nirum/Targets/Python.hs index c982e53..f556e9e 100644 --- a/src/Nirum/Targets/Python.hs +++ b/src/Nirum/Targets/Python.hs @@ -966,7 +966,11 @@ class $className(object): else: name = attribute_name try: - args[name] = deserialize_meta(field_types[name], item) + field_type = field_types[name] + except KeyError: + continue + try: + args[name] = deserialize_meta(field_type, item) except ValueError as e: errors.add('%s: %s' % (attribute_name, str(e))) if errors: @@ -1107,7 +1111,11 @@ class $className({T.intercalate "," $ compileExtendClasses annotations}): name = attribute_name tag_types = dict(cls.__nirum_tag_types__()) try: - args[name] = deserialize_meta(tag_types[name], item) + field_type = tag_types[name] + except KeyError: + continue + try: + args[name] = deserialize_meta(field_type, item) except ValueError as e: errors.add('%s: %s' % (attribute_name, str(e))) if errors: diff --git a/test/python/primitive_test.py b/test/python/primitive_test.py index ac1cb8e..ba9a064 100644 --- a/test/python/primitive_test.py +++ b/test/python/primitive_test.py @@ -138,10 +138,18 @@ def test_record(): point2_serialize = {'_type': 'point2', 'left': 3, 'top': 14} assert point2.__nirum_serialize__() == point2_serialize assert Point2.__nirum_deserialize__(point2_serialize) == point2 - with raises(ValueError): + with raises(ValueError): # no "_type" -- FIXME: "_type" is unnecessary Point2.__nirum_deserialize__({'left': 3, 'top': 14}) - with raises(ValueError): + with raises(ValueError): # no "left" and "top" fields Point2.__nirum_deserialize__({'_type': 'foo'}) + p = Point2.__nirum_deserialize__({ + # extra field does not matter; just ignored + '_type': 'point2', + 'left': 3, + 'top': 14, + 'extra': 'it does not matter', + }) + assert p == Point2(left=IntUnbox(3), top=IntUnbox(14)) with raises(TypeError): Point2(left=IntUnbox(1), top='a') with raises(TypeError): @@ -266,16 +274,24 @@ def test_union(): }) assert isinstance(name, MixedName.EastAsianName) with raises(ValueError) as e: - MixedName.__nirum_deserialize__({ + MixedName.__nirum_deserialize__({ # invalid field types '_type': 'mixed_name', '_tag': 'east_asian_name', - 'family_name': 404, - 'given_name': 503, + 'family_name': 404, # not a text + 'given_name': 503, # not a text }) assert str(e.value) == '''\ family_name: '404' is not a string. given_name: '503' is not a string.\ -''' +''' # message can contain multiple errors + n = MixedName.__nirum_deserialize__({ # invalid field types + '_type': 'mixed_name', + '_tag': 'east_asian_name', + 'family_name': u'John', + 'given_name': u'Doe', + 'extra': u'it does not matter', + }) + assert n == EastAsianName(family_name=u'John', given_name=u'Doe') def test_union_with_special_case(): From 3c233e8c32d65de17f0a44506310a93f7e57b6bc Mon Sep 17 00:00:00 2001 From: Hong Minhee Date: Thu, 1 Mar 2018 17:26:21 +0900 Subject: [PATCH 3/3] Release 0.3.1 --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index f26fe20..c711dac 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,7 +4,7 @@ Nirum changelog Version 0.3.1 ------------- -To be released. +Released on March 1, 2018. ### Python target