Skip to content

Conversation

@Holmes555
Copy link
Contributor

@Holmes555 Holmes555 commented May 5, 2023

Add PTBMongoDBJobStore as PTBSQLAlchemyJobStore example.

Fixed bug the same way as in PR.

It was tested manually.

@Bibo-Joshi Bibo-Joshi self-requested a review May 5, 2023 21:01
@Bibo-Joshi Bibo-Joshi self-assigned this May 5, 2023
Copy link
Member

@Bibo-Joshi Bibo-Joshi left a comment

Choose a reason for hiding this comment

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

Hi, thanks for the PR! IISC the addition basically does the same as sqlite jobstore, just with MongeDBJobStore as base class - is that right? I wonder if one could find a more general approach that accepts any JobStore implementation class as input and applies the changes to add/update_job as detailed below 🤔

@Holmes555
Copy link
Contributor Author

Hi, I think it could be done as Mixin class, but still every Storage should be separate class as in original apscheduler. All the storages could be put in one folder.

Copy link
Member

@Bibo-Joshi Bibo-Joshi left a comment

Choose a reason for hiding this comment

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

Thanks for the updates! I like the new unified structure 👍 IISC this now supersedes #73?

What I'm missing is unit tests for the mongodb jobstore. I guess it should be possible to parametrize the jq fixture in the ptb_sqlachlemy_jobstore in such a way that the tests run once with the sqlalchemy JS and once with the MongoDB jobstore.

@Holmes555
Copy link
Contributor Author

Spent 3 hours trying parametrize the fixtures, now I hate pytest. It's just not working like that, also would need to mock the mongodb, so basically there's nothing to test as the basic functionality was tested. So sorry, wouldn't do.

P.S. What is IISC?

@clot27
Copy link
Member

clot27 commented May 16, 2023

@Holmes555 IISC = If I see correctly

@Bibo-Joshi
Copy link
Member

An example of a parametrized fixture can be seen here:

https://github.com/python-telegram-bot/python-telegram-bot/blob/e432c296a9e76fb7613fcbf25b8ee5f4e1d86497/tests/conftest.py#L273-L278

I'm sure that providing a full-fledged mock of the mongodb is a lot of work and beyond the scope of this PR. however, we only want to ensure that update_job and add_job actually apply the workarounds for PTB, so I'm confident that you can get away with a minimally invasive mock :) Let me emphasize that unit tests should not be viewed as optional and avoidable chore, but are integral for ensuring stability of software and avoiding regressions.

Another note: Both the mongodb and the sqlalchemy jobstores define reconstitue_job by calling supers _restore_job. Is there a specific reason why you called the method PTBStoreAdapter._restore_job instead of directly calling it _reconstitute_job?

@Holmes555
Copy link
Contributor Author

Even with fixture parametrize I would need to mock the mongodb, and as I said the workarounds are the same as in PTBSQLAlchemyJobStore, because they both inherit from the PTBStoreAdapter, so it would be double tests.

For the _restore_job I called it like that to differ from the base _reconstitute_job as they are completely different. The same goes to _prepare_job. They shouldn't override base methods.

@Bibo-Joshi
Copy link
Member

Even with fixture parametrize I would need to mock the mongodb, and as I said the workarounds are the same as in PTBSQLAlchemyJobStore, because they both inherit from the PTBStoreAdapter, so it would be double tests.

Let me put it that way: Without explicit tests for PTBMongoDBJobStore, a PR could remove the complete body of that class and the CI would still pass. Even if you added unit tests that test PTBStoreAdapter itself, that would still not ensure that PTBMongeDBJobStore actually uses those.
Hence, adding unit tests for PTBMongoDBJobStore significantly reduces the risks of introducing regressions unintentionally.

For the _restore_job I called it like that to differ from the base _reconstitute_job as they are completely different. The same goes to _prepare_job. They shouldn't override base methods.

Ah, I had missed that, thanks!

@Holmes555 Holmes555 requested a review from Bibo-Joshi May 28, 2023 19:15
Copy link
Member

@Bibo-Joshi Bibo-Joshi left a comment

Choose a reason for hiding this comment

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

Thank you very much for taking the time to find a solution for the tests 👍

@Bibo-Joshi Bibo-Joshi merged commit 9073a25 into python-telegram-bot:main Jun 2, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jun 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] With ptb_sqlalchemy_jobstore exeception when rescheduling jobs

3 participants