Skip to content

Commit

Permalink
feat: add schema drop_unknown_fields
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Oct 20, 2024
1 parent 963f36f commit 4b14b09
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
10 changes: 10 additions & 0 deletions ckanext/transmute/logic/action/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ def mutate_fields(data: dict[str, Any], definition: SchemaParser, root: str):
"""
schema = definition.types[root]

known_fields: set[str] = set()

for field_name, field in sorted(schema["fields"].items(), key=_weighten_fields):
known_fields.add(field_name)

if field.remove:
data.pop(field_name, None)
continue
Expand Down Expand Up @@ -126,8 +130,14 @@ def mutate_fields(data: dict[str, Any], definition: SchemaParser, root: str):
)

if field.map:
known_fields.add(field.map)
data[field.map] = data.pop(field.name, None)

if schema.get("drop_unknown_fields"):
for name in list(data):
if name not in known_fields:
del data[name]


def _default_from(data, field: SchemaField):
default_from: Union[list[str], str] = field.get_default_from()
Expand Down
15 changes: 1 addition & 14 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
# -*- coding: utf-8 -*-
from setuptools import setup

setup(
# If you are changing from the default layout of your extension, you may
# have to change the message extractors, you can read more about babel
# message extraction at
# http://babel.pocoo.org/docs/messages/#extraction-method-mapping-and-configuration
message_extractors={
"ckanext": [
("**.py", "python", None),
("**.js", "javascript", None),
("**/templates/**.html", "ckan", None),
],
}
)
setup()

0 comments on commit 4b14b09

Please sign in to comment.