Add configurable record_transform hook for post-query record processing#1237
Open
aawemove wants to merge 1 commit into
Open
Add configurable record_transform hook for post-query record processing#1237aawemove wants to merge 1 commit into
aawemove wants to merge 1 commit into
Conversation
Introduces a configurable server.record_transform setting that accepts a file path or dotted module name. The referenced module must define a callable named record_transform which receives the SQLAlchemy ORM record object after database retrieval and must return it (optionally modified). The hook is applied before serialization across all supported protocols and output formats: - OGC API Records (JSON, HTML, application/xml) - CSW 2.0.2 and CSW 3.0 (all output schemas and profiles) Common use cases include filtering internal keywords, redacting sensitive field values, and normalizing output before it reaches clients. Adds unit tests and documentation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
pycsw currently offers no unified intervention point to modify records before they are returned to clients. Existing mechanisms are either format-specific (XSLT → CSW XML only, Jinja2 → OGC API HTML only) or absent entirely from the OGC API pipeline.
This PR introduces a
server.record_transformconfiguration option that accepts a file path or dotted module name pointing to a user-supplied Python callable. The callable receives the SQLAlchemy ORM record object after database retrieval and before serialization, and must return it (optionally modified). A single hook covers all supported protocols and output formats:pycsw serves metadata records in multiple formats, each with its own transformation mechanism:
xslt:configurationOperators who need to modify record content before delivery — for example, stripping internal keywords added at ingest time, redacting sensitive fields, or normalising values — must implement separate solutions for each format. There is no single point where a transformation can be applied uniformly across all protocols and output formats.
This PR closes that gap with a single hook that runs after database retrieval and before any format-specific serialization, making it unnecessary to maintain parallel format-specific workarounds.
Related Issue / Discussion
Additional Information
Full documentation for this feature is available in
docs/record-transform.rst, covering configuration, the two-representation model (individual fields vs.record.xml), format-specific serialization behaviour, an ISO 19139 example with raw XML rewriting, Docker volume injection, dotted module path support, and security considerations.Unit tests are located in
tests/unittests/test_record_transform.pyand cover loader behaviour (None/empty input, file loading, missing callable, missing module) as well as functional behaviour (keyword filtering, null keywords, identity passthrough).Example
transform.pyContributions and Licensing
(as per https://github.com/geopython/pycsw/blob/master/CONTRIBUTING.rst#contributions-and-licensing)