Skip to content

[18.0][FIX] queue_job: Fix TestJson#909

Open
Andrii9090-tecnativa wants to merge 1 commit intoOCA:18.0from
Tecnativa:18.0-fix-queue_job-tests
Open

[18.0][FIX] queue_job: Fix TestJson#909
Andrii9090-tecnativa wants to merge 1 commit intoOCA:18.0from
Tecnativa:18.0-fix-queue_job-tests

Conversation

@Andrii9090-tecnativa
Copy link

When a module adds a value in context, the tests fail.

For example:

  File "/opt/odoo/auto/addons/queue_job/tests/test_json_field.py", line 33, in test_encoder_recordset
    self.assertEqual(json.loads(value_json), expected)
AssertionError: {'_type': 'odoo_recordset', 'model': 'res.p[93 chars]ls'}} != {'uid': 6, '_type': 'odoo_recordset', 'mode[178 chars]ls'}}
  {'_type': 'odoo_recordset',
-  'context': {'lang': 'en_US', 'tz': 'Europe/Brussels'},
+  'context': {'lang': 'en_US',
+              'map_website_id': False,
+              'route_map_website_id': False,
+              'route_start_partner_id': 2,
+              'tz': 'Europe/Brussels'},
   'ids': [1],
   'model': 'res.partner',
   'su': False,
   'uid': 6}

  File "/opt/odoo/auto/addons/queue_job/tests/test_json_field.py", line 55, in test_encoder_recordset_list
    self.assertEqual(json.loads(value_json), expected)
AssertionError: Lists differ: ['a', 1, {'_type': 'odoo_recordset', 'model': 'res.p[94 chars]s'}}] != ['a', 1, {'uid': 6, '_type': 'odoo_recordset', 'mode[179 chars]s'}}]
First differing element 2:
{'_type': 'odoo_recordset', 'model': 'res.p[93 chars]ls'}}
{'uid': 6, '_type': 'odoo_recordset', 'mode[178 chars]ls'}}
  ['a',
   1,
   {'_type': 'odoo_recordset',
-   'context': {'lang': 'en_US', 'tz': 'Europe/Brussels'},
+   'context': {'lang': 'en_US',
+               'map_website_id': False,
+               'route_map_website_id': False,
+               'route_start_partner_id': 2,
+               'tz': 'Europe/Brussels'},
    'ids': [1],
    'model': 'res.partner',
    'su': False,
    'uid': 6}]

In this example, the partner_external_map module added map_website_id, route_map_website_id, and route_start_partner_id to the context, which caused the tests of queue_job to fail.

This fix ensures that only the keys returned by _job_prepare_context_before_enqueue_keys are preserved in the context, removing any additional values.

@pedrobaeza @christian-ramos-tecnativa could you review this PR?

In this case, when a module adds a value in context, the tests fail
@Andrii9090-tecnativa Andrii9090-tecnativa changed the title [FIX] queue_job: Fix TestJson [18.0][FIX] queue_job: Fix TestJson Mar 2, 2026
Copy link
Member

@amh-mw amh-mw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review only, LGTM.

Copy link
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the proper fix, but to control the context in the tests for not having that one, but you may want to have all the context keys serialized for any usage of it.

@Andrii9090-tecnativa
Copy link
Author

@pedrobaeza How can this be done, by modifying the _job_prepare_context_before_enqueue_keys method?

@pedrobaeza pedrobaeza added this to the 18.0 milestone Mar 2, 2026
@pedrobaeza
Copy link
Member

Seeing the module, I think the final test line should be changed from:

self.assertEqual(json.loads(value_json), expected)

to:

result_dict = json.loads(value_json)
for key in result_dict:
    self.assertEqual(result_dict[key], expected[key])

@christian-ramos-tecnativa

You could compare the jsons without the context and then loop through it as @pedrobaeza suggested

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

Successfully merging this pull request may close these issues.

4 participants