# Ansible Module Development: TypeError: Value of unknown type: \<class 'bson.objectid.ObjectId'\>, 5ec14572cce378f1d3df48eb

**URL:** <https://forum.ansible.com/t/ansible-module-development-typeerror-value-of-unknown-type-class-bson-objectid-objectid-5ec14572cce378f1d3df48eb/33034>\
**Category:** Ansible Developer\
**Created:** [May 27, 2020, 4:20pm UTC](https://forum.ansible.com/t/ansible-module-development-typeerror-value-of-unknown-type-class-bson-objectid-objectid-5ec14572cce378f1d3df48eb/33034 "2020-05-27T16:20:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rhysmeister](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/rhysmeister/32/10599_2.png) [@rhysmeister](https://forum.ansible.com/u/rhysmeister)\
**Post date:** [May 27, 2020, 4:20pm UTC](https://forum.ansible.com/t/ansible-module-development-typeerror-value-of-unknown-type-class-bson-objectid-objectid-5ec14572cce378f1d3df48eb/33034/1 "2020-05-27T16:20:50Z")

</div>

Hello,

I have started development of an Ansible module to insert a document into a MongoDB database. It’s over at [https://github.com/ansible-collections/community.mongodb/](https://github.com/ansible-collections/community.mongodb/)

When a MongoDB document is inserted, without providing a value for \_id, an Object ID is created automatically and returned. When this happens I get the following error…

> An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: Value of unknown type: \<class ‘bson.objectid.ObjectId’\>, 5ec14572cce378f1d3df48eb  
> 665  
> fatal: [testhost]: FAILED! =\> {“changed”: false, “module\_stderr”: “Traceback (most recent call last):\n File "/root/.ansible/tmp/ansible-tmp-1589724530.3062885-3682-27933782860899/AnsiballZ\_mongodb\_document.py", line 143, in \n \_ansiballz\_main()\n File "/root/.ansible/tmp/ansible-tmp-1589724530.3062885-3682-27933782860899/AnsiballZ\_mongodb\_document.py", line 135, in \_ansiballz\_main\n invoke\_module(zipped\_mod, temp\_path, ANSIBALLZ\_PARAMS)\n File "/root/.ansible/tmp/ansible-tmp-1589724530.3062885-3682-27933782860899/AnsiballZ\_mongodb\_document.py", line 81, in invoke\_module\n runpy.run\_module(mod\_name=‘ansible\_collections.community.mongodb.plugins.modules.mongodb\_document’, init\_globals=None, run\_name=‘ **main** ’, alter\_sys=True)\n File "/usr/lib/python3.6/runpy.py", line 205, in run\_module\n return \_run\_module\_code(code, init\_globals, run\_name, mod\_spec)\n File "/usr/lib/python3.6/runpy.py", line 96, in \_run\_module\_code\n mod\_name, mod\_spec, pkg\_name, script\_name)\n File "/usr/lib/python3.6/runpy.py", line 85, in \_run\_code\n exec(code, run\_globals)\n File "/tmp/ansible\_mongodb\_document\_payload\_oe81u9jo/ansible\_mongodb\_document\_payload.zip/ansible\_collections/community/mongodb/plugins/modules/mongodb\_document.py", line 483, in \n File "/tmp/ansible\_mongodb\_document\_payload\_oe81u9jo/ansible\_mongodb\_document\_payload.zip/ansible\_collections/community/mongodb/plugins/modules/mongodb\_document.py", line 479, in main\n File "/tmp/ansible\_mongodb\_document\_payload\_oe81u9jo/ansible\_mongodb\_document\_payload.zip/ansible/module\_utils/basic.py", line 2045, in exit\_json\n File "/tmp/ansible\_mongodb\_document\_payload\_oe81u9jo/ansible\_mongodb\_document\_payload.zip/ansible/module\_utils/basic.py", line 2038, in \_return\_formatted\n File "/tmp/ansible\_mongodb\_document\_payload\_oe81u9jo/ansible\_mongodb\_document\_payload.zip/ansible/module\_utils/basic.py", line 413, in remove\_values\n File "/tmp/ansible\_mongodb\_document\_payload\_oe81u9jo/ansible\_mongodb\_document\_payload.zip/ansible/module\_utils/basic.py", line 396, in \_remove\_values\_conditions\nTypeError: Value of unknown type: \<class ‘bson.objectid.ObjectId’\>, 5ec14572cce378f1d3df48eb\n”, “module\_stdout”: “”, “msg”: “MODULE FAILURE\nSee stdout/stderr for the exact error”, “rc”: 1}

If I specify an integer value for the \_id field Ansible doesn’t complain. The problem line of code is the following…

`inserted_id = deepcopy(str(client[database][collection].insert_one(document).inserted_id))`

The deepcopy and str cast were attempts to prevent the problem but Ansible still complains. I think this is a problem specific to something in Ansible. There’s probably not much point in a mongodb\_document module if I can’t support using a BSON ObjectId. Would anyone have a clue what this might be and if I can get around it?

Cheers,

Rhys
