Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some issues with test, update record, and rework realtime_updates example #6

Merged
merged 7 commits into from
Mar 3, 2024

Conversation

matthieuEv
Copy link
Contributor

Checklist

  • [ x ] I have read the Contribution Guidelines
  • [ x ] I have read and agree to the Code of Conduct
  • [ x ] I have read and agree that my contributions will be included under the project license
  • [ x ] I have added a description of my changes and why I want them or linked the relevant pull request below
  • [ x ] I have ran the formatter, linter and tests locally and ensured they give their all green
  • [ x ] If contributing new code: I've ensured my new code is covered sufficiently by unit and integration tests

Description of Changes

I have reworked the realtime_updates.py example which was giving an error: httpx.ConnectError: All connection attempts failed and added an exception handling system.

I fixed a bug in test_admin where the function def test_login(admin_client: PocketBase, admin: tuple[str, str]) was not in async and therefore returned an error when testing with pytest.

I modified the subscribe function in record.py to be more faithful to the Pocketbase documentation:

  • If the record_id is empty, an error is returned.
  • If it contains "*", then the subscription is made on all records in the collection.
  • If it contains a specific record_id, then the subscription is made on that particular record.

Related Issues

None

Copy link
Owner

@thijsmie thijsmie 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 for contributing! I have one remark which I'd like you to address before I merge this.

else:
return await self._pb.realtime.subscribe(self._collection, callback, options)
# No record ID provided, handle the case explicitly (e.g., raise an error)
raise ValueError("Invalid record_id: None")
Copy link
Owner

@thijsmie thijsmie Feb 28, 2024

Choose a reason for hiding this comment

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

I see your motivation for this change is "I modified the subscribe function in record.py to be more faithful to the Pocketbase documentation". I think that is invalid in this case: I do not like the magic "*" character meaning something in a function argument but I do think that making it value None is sufficient. Unlike Javascript we have a little bit more typing support. I'd ask you to either revert this change or split the subscribe function to a subscribe and a subscribe_all function or something.

@matthieuEv
Copy link
Contributor Author

I understand your point about the "*" character being non-standard and potentially confusing, especially given the stronger typing support in Python compared to Javascript.

While my initial goal was to align the function with the Pocketbase documentation, I agree that clarity and maintainability are important. Based on your suggestion, I'll split the subscribe function into two separate functions: subscribe (for specific record ID) and subscribe_all (for all records).

Thanks for your feedback

@thijsmie
Copy link
Owner

thijsmie commented Mar 1, 2024

I'll merge this as soon as the pipeline passes, seems you forgot to run the ruff formatter after your last change 😃

@matthieuEv
Copy link
Contributor Author

My Bad, totally forgot 🫠. This time it will work!

@thijsmie
Copy link
Owner

thijsmie commented Mar 3, 2024

Thank you @matthieuEv! In the future your PRs should automatically run the checks without me needing to approve them, allowing you to iterate a bit faster. I've also added a ci.bash script which you can run locally so you can test before pushing. I've just updated a test on your branch and rebased it on main to solve the merge conflict.

@thijsmie thijsmie merged commit e6e4573 into thijsmie:main Mar 3, 2024
2 checks passed
@matthieuEv
Copy link
Contributor Author

That sounds perfect to me. I'll be sure to use the bash script for local testing, it will help a lot, thanks!

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.

2 participants