Opened 21 months ago
Closed 21 months ago
#35179 closed Bug (fixed)
Admindocs does not recognize methods containing positional-only arguments or keyword-only arguments as such
| Reported by: | David Sanders | Owned by: | Salvo Polizzi |
|---|---|---|---|
| Component: | contrib.admindocs | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Given the model:
class Foo(Model):
def arg_kwarg_method(self, arg, kwarg=None): ...
def posarg_only_method(self, posarg, /): ...
def kwarg_only_method(self, *, kwarg): ...
def posarg_only_and_kwarg_only_method(self, posarg, /, *, kwarg): ...
def posarg_only_and_arg_and_kwarg_only_method(self, posarg, /, arg, *, kwarg): ...
The following are documented as methods:
arg_kwarg_method()posarg_only_method()posarg_only_and_kwarg_only_method()
The following are documented as attributes:
kwarg_only_method()posarg_only_and_arg_and_kwarg_only_method()
Attachments (1)
Change History (10)
comment:1 by , 21 months ago
| Description: | modified (diff) |
|---|---|
| Summary: | Admindocs omits model methods containing only keyword-only arguments → Admindocs treats model some model methods containing positional-only arguments or keyword-only arguments as attributes |
by , 21 months ago
| Attachment: | admindocs.png added |
|---|
comment:2 by , 21 months ago
| Triage Stage: | Unreviewed → Accepted |
|---|---|
| Version: | 5.0 → dev |
After some investigation, this definitely seems like a valid issue. I did some initial debugging, and both methods are being detected as fields because the guard (in django/contrib/admindocs/views.py:ModelDetailView):
elif ( method_has_no_args(func) and not func_accepts_kwargs(func) and not func_accepts_var_args(func) ): fields.append( { "name": func_name, "data_type": get_return_data_type(func_name), "verbose": verbose or "", } )
is being evaluated with these values:
method_has_no_args(func)=True func_accepts_kwargs(func)=False func_accepts_var_args(func)=False
The methods func_accepts_kwargs and func_accepts_var_args need to be updated to understand the * and / syntax (new since Python 3.8).
David, would you like to prepare a patch? :-)
comment:3 by , 21 months ago
| Summary: | Admindocs treats model some model methods containing positional-only arguments or keyword-only arguments as attributes → Admindocs does not recognize methods containing positional-only arguments or keyword-only arguments as such |
|---|
comment:4 by , 21 months ago
| Has patch: | set |
|---|---|
| Needs tests: | set |
comment:5 by , 21 months ago
| Needs tests: | unset |
|---|
comment:6 by , 21 months ago
| Needs tests: | set |
|---|---|
| Patch needs improvement: | set |
Hi Salvo,
Thanks for picking this up. You're in the right areaa but the patch provided appears to break the patched functions.
My advice is to start with creating a test for admindocs first then take a look at the function method_has_no_args(). The fix should be the same for ticket #35175 👍
comment:7 by , 21 months ago
| Needs tests: | unset |
|---|---|
| Patch needs improvement: | unset |
comment:8 by , 21 months ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
| Triage Stage: | Accepted → Ready for checkin |
Screenshot of admindocs treating some methods as attributes