-
Notifications
You must be signed in to change notification settings - Fork 248
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: get param's regex pattern from part path #510
fix: get param's regex pattern from part path #510
Conversation
hi @jtamm-red let me get you some quick feedback before you continue working on this. some time ago i implemented a state machine to extract the regex: so the issue is not using the regex, but when exactly to use the regex and not the other methods. since this has implications, i'm currently weighing the options. your implementation is a duplication of existing functionality, which is heavily tested. at the moment this PR has a very low chance to be merged, but the underlying problem may get tackled soon. |
Codecov Report
@@ Coverage Diff @@
## master #510 +/- ##
==========================================
- Coverage 98.58% 98.54% -0.04%
==========================================
Files 57 57
Lines 5724 5785 +61
==========================================
+ Hits 5643 5701 +58
- Misses 81 84 +3
Continue to review full report at Codecov.
|
Hello, @tfranzel I removed duplicated function and solved tests (unit). But one problem: parameter 'pk' type cannot be string. Some tests are broken, when parameter 'pk' type is string. Unfortunately tests (unit) failed on other django version. Can you check and fix it? |
@jtamm-red, as i said:
the failing tests are part of the problem. it changes the processing order and that side effect may potentially break a lot of existing users. it is a change that needs to be carefully weighed. the change itself is easy. this snipped would theoretically be the only change: def resolve_regex_path_parameter(path_regex, variable, available_formats):
for match in _PATH_PARAMETER_COMPONENT_RE.finditer(path_regex):
UNCHANGED_CODE
regex_groups = analyze_named_regex_pattern(path_regex)
if variable in regex_groups and regex_groups[variable] != '[^/.]+':
return build_parameter_type(
name=variable,
schema={
**build_basic_type(OpenApiTypes.STR),
'pattern': regex_groups[variable]
},
location=OpenApiParameter.PATH,
)
return None |
@jtamm-red please have a look at #511 . it addresses this issue and a bunch of related problems. #511 supersedes this PR, but nonetheless thank you for your initiative and input. |
I got warning log:
could not derive type of path parameter "code" because because it is untyped and obtaining queryset from the viewset failed. Consider adding a type to the path (e.g. <int:code>) or annotating the parameter type with @extend_schema. Defaulting to "string