Skip to content

Commit e0a6dfc

Browse files
Andersson007oraNodmattclay
authored
porting_guide_core_2.19.rst: add clatifications on the required non-string key conversion (#2560)
* porting_guide_core_2.19.rst: add clatifications on the required non-string key conversion * Update docs/docsite/rst/porting_guides/porting_guide_core_2.19.rst Co-authored-by: Don Naro <[email protected]> * Update docs/docsite/rst/porting_guides/porting_guide_core_2.19.rst Co-authored-by: Don Naro <[email protected]> * Add an example how to convert * Add example * Change example * Update docs/docsite/rst/porting_guides/porting_guide_core_2.19.rst Co-authored-by: Matt Clay <[email protected]> * Update docs/docsite/rst/porting_guides/porting_guide_core_2.19.rst Co-authored-by: Matt Clay <[email protected]> * Update docs/docsite/rst/porting_guides/porting_guide_core_2.19.rst Co-authored-by: Matt Clay <[email protected]> * Update docs/docsite/rst/porting_guides/porting_guide_core_2.19.rst * Update docs/docsite/rst/porting_guides/porting_guide_core_2.19.rst Co-authored-by: Matt Clay <[email protected]> --------- Co-authored-by: Don Naro <[email protected]> Co-authored-by: Matt Clay <[email protected]>
1 parent 9424c8c commit e0a6dfc

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

docs/docsite/rst/porting_guides/porting_guide_core_2.19.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,29 @@ Values formerly represented by that type will now appear as a tagged ``str`` ins
650650
Special handling in plugins is no longer required to access the contents of these values.
651651

652652

653+
No implicit conversion of non-string dict keys
654+
----------------------------------------------
655+
656+
In previous versions, ``ansible-core`` relied on Python's ``json.dumps`` to implicitly convert ``int``, ``float``, ``bool`` and ``None`` dictionary keys to strings in various scenarios, including returning of module results.
657+
For example, a module was allowed to contain the following code:
658+
659+
.. code-block:: python
660+
661+
oid = 123
662+
d = {oid: "value"}
663+
module.exit_json(return_value=d)
664+
665+
Starting with this release, modules must explicitly convert any non-string keys to strings (for example, by using the ``str()`` Python function) before passing dictionaries to the ``AnsibleModule.exit_json()`` method of ``ansible-core``. The above code must be changed as follows:
666+
667+
.. code-block:: python
668+
669+
oid = 123
670+
d = {str(oid): "value"}
671+
module.exit_json(return_value=d)
672+
673+
If you encounter ``"[ERROR]: Task failed: Module failed: Key of type '<NON-STRING>' is not JSON serializable by the 'module_legacy_m2c' profile.``, it indicates that the module that is used in the task does not perform the required key conversion.
674+
675+
653676
Command Line
654677
============
655678

0 commit comments

Comments
 (0)