Находки в опенсорсе: Python
1.06K subscribers
5 photos
332 links
Легкие задачки в опенсорсе из мира Python

Чат: @opensource_findings_chat
Download Telegram
🚀 New issue to wemake-services/django-modern-rest by @sobolevn
📝 Provide faster JWT decode and encode options with `msgspec` (#1390)


When msgspec is installed, we can speed up the pyjwt encode and decode.

By default it uses the default json module for both convertions:

1. https://github.com/jpadilla/pyjwt/blob/7144e4534c34810f4525dc4578a32addd8212cff/jwt/api_jwt.py#L156-L172
2. https://github.com/jpadilla/pyjwt/blob/7144e4534c34810f4525dc4578a32addd8212cff/jwt/api_jwt.py#L287-L301

We can provide our own PyJWT subclass and make the process faster. Since JWT is a hot path, even a smaller boost will be a massive win overall.

This will require a benchmark test :)


#feature #good_first_issue #help_wanted #security #opensource_september #django_modern_rest
sent via relator
🚀 New issue to wemake-services/django-modern-rest by @sobolevn
📝 Cache OpenAPI views schema generation (#1398)


Currently, our OpenAPI views are really slow, because they recompute the schema on each request. Which is a bad thing if this schema is publicly available and has a lot of traffic.

Example:

django-modern-rest/dmr/openapi/views/json.py

Lines 28 to 30 in 06626f9

Proposal: we need to cache the schema generation. Not the view itself, because it can be cached by the user via a decorator. This might go to the docs as an example.

@cachedproperty seems like the best solution here.


#feature #good_first_issue #help_wanted #openapi #opensource_september #django_modern_rest
sent via relator
🚀 New issue to wemake-services/django-modern-rest by @sobolevn
📝 Rename `json_dump` to `json_dumps` (#1399)


json.dump works with files, while json.dumps works with strings, which is the case here:

django-modern-rest/dmr/internal/json.py

Lines 109 to 120 in 06626f9

We need to rename our helpers from json_dump to json_dumps and list this as a breaking change.


#bug #good_first_issue #help_wanted #opensource_september #django_modern_rest
sent via relator
1
🚀 New issue to faststream-community/zMQTT by @borisalekseev
📝 MQTT 5: expose structured metadata from broker DISCONNECT packets (#89)


Problem

In zmqtt 0.2.1, a broker DISCONNECT becomes a generic MQTTDisconnectedError containing the reason code only in its message text. Decoded Reason String, User Properties, and Server Reference are discarded. Applications cannot reliably inspect why the broker closed the connection.

The relevant paths are _dispatch(), DisconnectProperties, and MQTTDisconnectedError.

Expected behavior

Implement support for MQTT 5 §3.14, DISCONNECT:

• Expose the broker's reason_code, Reason String, User Properties, and Server Reference as structured public data.
• Make the event observable even when automatic reconnect subsequently succeeds.
• Preserve these details when a broker disconnect is propagated to affected callers.
• Distinguish a broker DISCONNECT from a transport failure where no MQTT reason code was received.
• Keep duplicate User Property keys and avoid requiring applications to parse exception text.

Related: #85 exposes the corresponding CONNACK metadata. Following Server Reference is a separate feature.


#good_first_issue #opensource_september #faststream #zmqtt
sent via relator
🚀 New issue to wemake-services/wemake-python-styleguide by @sobolevn
📝 Do not count docstrings for `WPS226` (#3803)


dmr/security/jwt/views.py

155:9 WPS226 Found string literal over-use: 'Lazy endpoint spec.' 6 > 3
"""Lazy endpoint spec."""
^

I just got this, where """Lazy endpoint spec.""" is an actual docstring.
This is not right.


#bug #help_wanted #levelstarter #good_first_issue #wemake_python_styleguide #wps
sent via relator
🚀 New issue to wemake-services/django-modern-rest by @sobolevn
📝 Add controller-level `tags` (#1434)


For some reason we don't have tags that can be defined for all endpoints in the controller. We only have per-endpoint and per-router:

django-modern-rest/dmr/endpoint.py

Lines 288 to 292 in 87a02f5

So, let's add controller level tags support as well.


#feature #good_first_issue #help_wanted #openapi #opensource_september #django_modern_rest
sent via relator
🚀 New issue to wemake-services/django-modern-rest by @sobolevn
📝 Remove OpenAPI 3.0.x support (#1435)


We claimed that we supported OpenAPI 3.0.x, but this was never the case, we always supported a subset of 3.0.x, because only 3.1 started supporting JsonSchema that we use for our models.

We need to remove the support from both docs and code.


#bug #good_first_issue #help_wanted #openapi #opensource_september #django_modern_rest
sent via relator
🚀 New issue to wemake-services/django-modern-rest by @sobolevn
📝 Explain why `openapi_examples_seed` option is not supported per controller and per endpoint (#1436)


Most of our settings can be modified on endpoint and controller levels. But, not this one. Why? Because schemas are generated only globally and can be reused by multiple endpoints and controllers. We need to explain this in the setting docs.


#documentation #good_first_issue #help_wanted #openapi #opensource_september #django_modern_rest
sent via relator
🚀 New issue to wemake-services/django-modern-rest by @sobolevn
📝 Make sure all `bool` values in `dmr.openapi.objects` can also accept `None` (#1437)


Why is this important? Because we ignore None values from the schema dump. But, now all deprecated: False objects are dumped. This is the default, no need to do this.

We need to:

• Update bool = False to be bool | None = None
• Update all snapshots to remove exising values

All Nones will be ignored.


#feature #good_first_issue #help_wanted #openapi #opensource_september #django_modern_rest
sent via relator
🚀 New issue to wemake-services/django-modern-rest by @sobolevn
📝 Improve `re_path` default parameter schema (#1439)


Currently we default to str as schema for all patterns in re_path. However, this is not the only thing we can do. We can also copy the pattern itself to the schema. Example:

re_path(r'^v(?P<version>\d+)/$', VersionController.as_view())  # schema: {type: string}

We can copy the pattern as well:

# re_path (?P<version>\d+)
- name: version
in: path
schema: {type: string, pattern: '^\d+$'}

This way users would have more info about what is expected.
See

django-modern-rest/dmr/openapi/generators/component_parsers.py

Lines 136 to 152 in 87a02f5

for current schema generation.


#feature #good_first_issue #help_wanted #openapi #opensource_september #django_modern_rest
sent via relator
🚀 New issue to wemake-services/django-modern-rest by @sobolevn
📝 Improve path customization tests, `__dmr_converter_schema__` is never tested (#1440)


Currently we claim to support __dmr_converter_schema__ attribute to customize how Django path converters generate schema, but we never actually test it.

See

django-modern-rest/dmr/openapi/generators/component_parsers.py

Lines 117 to 123 in 87a02f5

We need at least two tests:

• Valid customization
• Invalid one that will fail the final schema validation

#bug #good_first_issue #help_wanted #opensource_september #django_modern_rest
sent via relator
🚀 New issue to wemake-services/django-modern-rest by @sobolevn
📝 Support `SlugConverter` and `PathConverter` from Django in path parameters (#1441)


Currently we only support int and uuid converters from django:

django-modern-rest/dmr/openapi/generators/component_parsers.py

Lines 36 to 41 in 87a02f5

However, there are two more that we can support:

path, we can add {"description": "Can contain slashes"} to the schema
slug, we can add the pattern from SlugConverter

This needs to be tested. Probably we can also change the storage API. I am not sure how currently represent in for all possible providers. Probably we can store prepared schemas for types that exist.


#feature #good_first_issue #help_wanted #openapi #opensource_september #django_modern_rest
sent via relator
🚀 New issue to wemake-services/django-modern-rest by @sobolevn
📝 Ensure that you can include abstract controllers in `Router` (#1445)


Currently Router will say nothing if you try to include Controller with is_abstract == True into the url patterns.

I propose changing as_view logic here:

django-modern-rest/dmr/controller.py

Lines 209 to 223 in 87a02f5

.as_view() must be impossible to call on the abstract controller.
Raise EndpointMetadataError for this case.


#feature #good_first_issue #help_wanted #opensource_september #django_modern_rest
sent via relator
🚀 New issue to wemake-services/django-modern-rest by @sobolevn
📝 Parse `summary` and `description` from `Controller` for `PathItem` docs (#1446)


Currently we don't parse summary and description from docstrings for controllers, only for endpoints. This is not good.

django-modern-rest/dmr/controller.py

Lines 553 to 561 in 87a02f5

What we can do instead?

• Use Empty as the default value for Controller.summary and Controller.description
• If it is empty, parse summary and description from the docstring, just like EndpointMetadata does
• If it is explicitly None, then do nothing
• Test this
• Update all existing snapshots

#feature #good_first_issue #help_wanted #openapi #opensource_september #django_modern_rest
sent via relator
🚀 New issue to wemake-services/django-modern-rest by @sobolevn
📝 Fix docs in the `pyproject.toml` (#1447)


Currently some links and comments are moved due to pyproject-fmt hook, examples:

django-modern-rest/pyproject.toml

 Line 556 in 87a02f5

django-modern-rest/pyproject.toml

 Line 408 in 87a02f5

They should be at the top of their sections.

We also need to remove empty sections like:

django-modern-rest/pyproject.toml

 Line 497 in 87a02f5

This is a very simple issue, please keep it for people who make their first commit :)


#documentation #good_first_issue #help_wanted #opensource_september #django_modern_rest
sent via relator
🚀 New issue to wemake-services/django-modern-rest by @sobolevn
📝 Increase `DMR_MAX_CACHE_SIZE` to be `1024` (#1448)


django-modern-rest/dmr/envs.py

Line 8 in 87a02f5

I think that we defined a very small default for this value. There can be way more schemes than 256 on a big project. We want to have cache by default on them.

So, use a bigger number :)


#feature #good_first_issue #help_wanted #opensource_september #django_modern_rest
sent via relator
🚀 New issue to wemake-services/django-modern-rest by @sobolevn
📝 Create pair of JWT tokens for the docs (#1450)


Currently we can't run examples that involve JWT auth, but we have a lot of such examples. So, we need to create a pair of JWT tokens and be able to use them in # run comments the same way we use / run examples with Token auth.

Examples:

• Auth:

 django-modern-rest/docs/examples/auth/token/revoke_token.py

 Lines 11 to 23 in 87a02f5

django-modern-rest/docs/tools/sphinx_ext/run_examples.py

 Lines 951 to 952 in 87a02f5

Btw, also remove Token support from Query, since we don't use it anymore:

django-modern-rest/docs/tools/sphinx_ext/run_examples.py

Lines 840 to 844 in 87a02f5


#documentation #feature #good_first_issue #help_wanted #opensource_september #django_modern_rest
sent via relator
🚀 New issue to wemake-services/django-modern-rest by @sobolevn
📝 Support `default` values for `TypeVar` when using controller type var inference (#1452)


We have a TODO here:

django-modern-rest/dmr/types.py

Lines 318 to 326 in 405ba9b

We either need to:

1. Support the typevars with defaults, add tests, remove TODO
2. Or just add tests and remove TODO if it is already supported

#feature #good_first_issue #help_wanted #opensource_september #django_modern_rest
sent via relator
🚀 New issue to wemake-services/django-modern-rest by @sobolevn
📝 Improve the performance of `_run_checks` and `_run_async_checks` (#1454)


Currently we have two functions with logic on how to run endpoint checks:

django-modern-rest/dmr/endpoint.py

Lines 417 to 425 in 405ba9b

and then we check inside each call if this call was even needed:

django-modern-rest/dmr/endpoint.py

Lines 427 to 432 in 405ba9b

CALL is not a cheap operation in Python, so I propose a different design.
We should check if the call is needed before the call itself. And only call parts that are actually required.

This is especially important for the async code:

django-modern-rest/dmr/endpoint.py

Lines 460 to 471 in 405ba9b

Where we are awaiting 4 indeprendent coroutines.
We should not, if possible.


#good_first_issue #help_wanted #performance #opensource_september #django_modern_rest
sent via relator
🚀 New issue to wemake-services/django-modern-rest by @sobolevn
📝 Cache the negotiation parts (#1455)


Most of the headers are simple and repeatable. Most users will just send Content-Type: application/json and Accept: application/json like 99% of the time. So, there's no need to run the negotiation process the second time. We already know the final result. So, go through the https://github.com/wemake-services/django-modern-rest/blob/master/dmr/negotiation.py and find places where we can cache header_value -> parser_class or header_value -> renderer_class computations.

Prefer not to have any API changes here.


#good_first_issue #help_wanted #performance #opensource_september #django_modern_rest
sent via relator