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

render_cell documentation example doesn't match the method signature #1826

Closed
pjamargh opened this issue Sep 28, 2022 · 3 comments
Closed

render_cell documentation example doesn't match the method signature #1826

pjamargh opened this issue Sep 28, 2022 · 3 comments

Comments

@pjamargh
Copy link

Open Datasette stable doc at https://docs.datasette.io/en/stable/plugin_hooks.html?highlight=render_cell#render-cell-row-value-column-table-database-datasette

render_cell plugin hook method signature is render_cell(row, value, column, table, database, datasette), the example shown inline uses render_cell(value).

image

@simonw
Copy link
Owner

simonw commented Sep 28, 2022

This is deliberate. The Datasette plugin system allows you to specify only a subset of the parameters for a hook - in this example, only the value is needed so the others can be omitted.

There's a note about this at the very top of that documentation page: https://docs.datasette.io/en/stable/plugin_hooks.html#plugin-hooks

When you implement a plugin hook you can accept any or all of the parameters that are documented as being passed to that hook.

For example, you can implement the render_cell plugin hook like this even though the full documented hook signature is render_cell(value, column, table, database, datasette):

@hookimpl
def render_cell(value, column):
    if column == "stars":
        return "*" * int(value)

@simonw simonw closed this as completed Sep 28, 2022
@simonw
Copy link
Owner

simonw commented Sep 28, 2022

Though now I notice that the copy right there needs to be updated to reflect the new row parameter to render_cell!

@pjamargh
Copy link
Author

pjamargh commented Sep 28, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants