question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`add_tasks_from` modifying the application?

See original GitHub issue

Hi @ewjoachim,

In our test environment, we use pytest and are trying to monkeypatch our async procrastinate application as follows:

@pytest.fixture
async def patch_async_app(monkeypatch: pytest.MonkeyPatch):
    original_app = main.procrastinate_app
    with monkeypatch.context() as mp:
        in_memory_async_app = App(connector=InMemoryConnector())
        in_memory_async_app.add_tasks_from(original_app, namespace="original")
        mp.setattr(main, "procrastinate_app", in_memory_async_app)
        yield in_memory_async_app
        in_memory_async_app.connector.reset()

The first test that uses this fixture passes just fine with these log entries:

[cloud-app] INFO:procrastinate.jobs:job_defer app.gql_mutations.defer_create_namespace_in_k8s[5]({'namespace': 'tenant-test-org1-b78d-test'})
[cloud-app-worker-k8s] INFO:procrastinate.worker.k8s-worker:start_job app.gql_mutations.defer_create_namespace_in_k8s[5]({'namespace': 'tenant-test-org1-b78d-test'})

(Note that we only recently started using the InMemoryConnector in tests so we have some fixtures/test code that relies on actually enqueuing a task that is then picked up by a procrastinate worker, so in effect we have both in-memory and the “normal” task pipelines when we run these tests.)

However, the next test (using the exact same fixtures) then fails with the following logs:

[cloud-app] INFO:procrastinate.jobs:job_defer original:app.gql_mutations.defer_create_namespace_in_k8s[3]({'namespace': 'tenant-test-org2-c40f-test'})

Interestingly/strangely, the app name is now namespaced original:app, which I can only assume is coming from our add_tasks_from usage above since we pass namespace="original" there and only there.

Is it possible that add_tasks_from is doing some kind of mutation of the app object, or am I just doing something stupid that I can’t yet see?

Thanks for your time! 😅

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
ewjoachimcommented, Apr 5, 2022
send_risk_score_event_task.blueprint = in_memory_async_app

You may want to undo that after the yield, otherwise you’ll end up keeping a reference to the in memory app forever in your tests.

1reaction
ewjoachimcommented, Apr 1, 2022

Hey @mecampbellsoup ! Thanks for taking the time to make a detailed ticket !

I could be wrong, but I believe that rather than add_tasks_from which is a method that’s been introduced for blueprints (so making re-usable groups of tasks), what you’re looking for is with_connector which I think is closer from what you’re trying to do.

Let me know if changing this is enough for your usecase. Also, if it works, and if you have opinions on what should be changed in the docs to make this more obvious for the next people, please either point it or do a PR 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add or edit a task - Android - Google Tasks Help
Open the Google Tasks app Tasks . · Tap Add task . · Enter a title. · Optional: To add more info, tap...
Read more >
Assign and track tasks - Microsoft Support
On the navigation bar, click Tasks, and then click New Task, or open an existing task. Keyboard shortcut To create a task, press...
Read more >
Adding Tasks to Task Lists - Oracle Help Center
Define a task list by clicking Create Task List icon , and then entering a name. Modify a task list to add a...
Read more >
Modifying tasks - IBM
In the Modification tab, click a task property in the Task Modifications list, enable the property to make it editable, and specify appropriate...
Read more >
Tasks in Visual Studio Code
Extensions can also contribute tasks using a Task Provider, and these contributed tasks can add workspace-specific configurations defined in the tasks.json file ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found