Closed ChristianF88 closed 1 month ago
Hello, @ChristianF88! I'm not planning to implement the support for the ckan-2.9.11 version, but you can fork the repo and do it on your own.
ckan.types
module and replace it with dict[str, Any]
, As for the second error, I suggest you try to alter the action like this:
@tk.side_effect_free
def get_archive_structure(context, data_dict):
data_dict, errors = tk.navl_validate(
data_dict,
{
"id": [
tk.get_validator("not_empty"),
tk.get_validator("unicode_safe"),
tk.get_validator("resource_id_exists"),
],
"view_id": [
tk.get_validator("not_empty"),
tk.get_validator("unicode_safe"),
tk.get_validator("resource_view_id_exists"),
],
},
)
if errors:
raise tk.ValidationError(errors)
resource = tk.get_action("resource_show")(context, {"id": data_dict["id"]})
resource_view = tk.get_action("resource_view_show")(
context, {"id": data_dict["view_id"]}
)
try:
return [
n.model_dump() if isinstance(n, unf_types.Node) else n
for n in unf_utils.get_archive_tree(resource, resource_view)
]
except unf_exception.UnfoldError as e:
return {"error": str(e)}
We remove the validate
decorator and move the schema validation inside the function body.
Thanks @mutantsan! I'll definitely have a look at it. Which ckan version does the code work with? That would be helpful to know, then I can also have a look at the official Changelog.
It was written for CKAN 2.10+. I had to specify it in the readme, but forgot to do it 😞
Closing this issue. Feel free to reopen it if you have other questions.
Hi @mutantsan,
I spent some time today on making the code ckan 2.9 compatible. I got it running without errors, but the extension doesn't work properly. When I create a view the extension gets stuck here:
At this point I will not spend more time on this, once we update to CKAN 2.10, I'll be back ;)
Here's a list of the necessary changes, in case someone else wants to tackle this:
1) Remove ckan type hints (plugin.py, validator.py)
2) Add validator_args
(without type hints) to schema.py:
from functools import wraps
from ckan.logic import get_validator
import inspect
# Copied from CKAN 2.10, removed type hints
def validator_args(fn):
"""Collect validator names from argument names and pass them to wrapped
function.
Example::
@validator_args
def schema_function(not_empty, ignore):
return not_empty, ignore
ne, ig = schema_function()
assert ne is get_validator("not_empty")
assert ig is get_validator("ignore")
"""
args = inspect.signature(fn).parameters
@wraps(fn)
def wrapper():
kwargs = {
arg: get_validator(arg)
for arg in args}
return fn(**kwargs)
return wrapper
...
3) Remove blanket
decorators (@tk.blanket.actions, @tk.blanket.validators) from plugin.py, as they were introduced in CKAN 2.10.
Hi @mutantsan and @mutantsanya,
your ckanext looks promising. I am trying to get it working with my ckan 2.9.11 instance.
Unfortunately I keep on getting errors.
1) NoModuleError for
ckan.types
caused by these imports for type hints https://github.com/mutantsan/ckanext-unfold/blob/36ce00933388d6dd4dd128c05d8f91a614c31167/ckanext/unfold/plugin.py#L7 and https://github.com/mutantsan/ckanext-unfold/blob/36ce00933388d6dd4dd128c05d8f91a614c31167/ckanext/unfold/logic/validators.py#L42) If I remove the type hints, the problem becomes:
Do you have any advice on how to get the extension working?
Cheers!