Skip to content

Commit

Permalink
fix: clear validators cache in declare_config_options to use custom v…
Browse files Browse the repository at this point in the history
…alidator
  • Loading branch information
mutantsan committed Jul 12, 2024
1 parent 1bb1011 commit a100082
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion ckanext/charts/plugin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from __future__ import annotations

from typing import Any
from os import path

from yaml import safe_load

import ckan.plugins as p
import ckan.plugins.toolkit as tk
import ckan.logic as logic
from ckan import types
from ckan.common import CKANConfig
from ckan.config.declaration import Declaration, Key

import ckanext.charts.config as conf
import ckanext.charts.utils as utils
Expand All @@ -17,10 +22,10 @@

@tk.blanket.helpers
@tk.blanket.blueprints
@tk.blanket.config_declarations
@tk.blanket.validators
class ChartsViewPlugin(p.SingletonPlugin):
p.implements(p.IConfigurer)
p.implements(p.IConfigDeclaration)
p.implements(p.IResourceView)
p.implements(p.IBlueprint)
p.implements(p.ISignal)
Expand All @@ -43,6 +48,17 @@ def update_config(self, config_: CKANConfig):
tk.add_public_directory(config_, "public")
tk.add_resource("assets", "charts")

# IConfigDeclaration

def declare_config_options(self, declaration: Declaration, key: Key):
"""Allow usage of custom validators by clearing the validators cache"""
logic.clear_validators_cache()

with open(path.dirname(__file__) + "/config_declaration.yaml") as file:
data_dict = safe_load(file)

return declaration.load_dict(data_dict)

# IResourceView

def info(self) -> dict[str, Any]:
Expand Down

0 comments on commit a100082

Please sign in to comment.