Skip to content

Conversation

@A-Souhei
Copy link

CKAN 2.11 and Python 3.10 Compatibility

Summary

This PR updates ckanext-scheming for full compatibility with CKAN 2.11 and Python 3.10. All 157 tests now pass successfully in both CKAN 2.10 and CKAN 2.11 environments.

Changes

Core Compatibility Fixes

  1. Form Selectors (CKAN 2.11)

    • Updated organization and group form selectors to handle CKAN 2.11's page structure changes
    • Edit forms moved from position [1] to [2] due to additional search form
    • Added version-aware form selection in test helpers
  2. Test Infrastructure

    • Updated test helper functions for CKAN 2.10+ authentication (headers vs extra_environ)
    • Fixed Flask URL patterns for resource and dataset forms
    • Added sysadmin_env fixture support across all form tests
    • Corrected parameter names (type_ instead of type) for custom org/group tests
  3. Assets Migration

    • Migrated from fanstatic to webassets (CKAN 2.10+ requirement)
    • Added webassets.yml configuration
    • Added asset loading templates (base.html, scheming_asset.html)
  4. Configuration Declarations

    • Added declare_config_options() method for CKAN 2.9+ config system
    • Properly declares scheming.dataset_schemas, scheming.organization_schemas, scheming.group_schemas
  5. Template Updates

    • Added missing form snippet templates (multiple_text, number, radio, repeating_subfields)
    • Added organization edit_base template
    • All templates support both CKAN 2.10 and 2.11

Test Results

Before

  • CKAN 2.11: 11 failed, 146 passed (93%)
  • CKAN 2.10: 6 failed, 151 passed (96%)

After

  • CKAN 2.11: 157 passed (100%)
  • CKAN 2.10: 157 passed (100%)

Files Changed

  • ckanext/scheming/plugins.py - Config declarations
  • ckanext/scheming/tests/test_form.py - Test helper functions and form selectors
  • ckanext/scheming/templates/organization/edit_base.html - NEW
  • ckanext/scheming/templates/scheming/form_snippets/*.html - NEW (4 files)
  • PROGRESS.md - Detailed migration documentation

Breaking Changes

None. All changes are backward compatible with CKAN 2.10.

Security Review

✅ No security issues introduced

  • No hardcoded credentials or secrets
  • All templates copied from upstream without modification
  • Proper attribute access using hasattr()
  • Safe default values

Testing

All tests pass in both environments:

./run_tests.sh

Related Issues

Fixes compatibility issues with:
- Python 3.10
- CKAN 2.11
- Flask-based routing
- Webassets (replacing fanstatic)

Migration Notes

This PR completes the CKAN 2.11 migration. The extension now:
- ✅ Supports Python 3.10
- ✅ Supports CKAN 2.11
- ✅ Uses webassets instead of fanstatic
- ✅ Uses Flask URL patterns
- ✅ Declares all config options properly
- ✅ Maintains backward compatibility with CKAN 2.10

This commit resolves multiple compatibility issues to make ckanext-scheming
work with CKAN 2.11 and Python 3.10:

1. Added missing dependencies (pycountry, ckanapi) to setup.py
2. Updated pytest to version 7.x for Python 3.10 compatibility
3. Fixed jinja2 Markup import for jinja2 3.0+ compatibility
4. Fixed validator resolution to use unicode_safe function instead of str type
5. Created separate decorators.py module for scheming_validator decorator
6. Updated all schema files to use unicode_safe instead of unicode validator
7. Removed six.text_type from default validators in plugins.py
8. Fixed auto_create_valid_name validator to prevent infinite loops

Files modified:
- setup.py: Added pycountry and ckanapi dependencies
- test-requirements.txt: Updated pytest and pytest-cov versions
- ckanext/scheming/decorators.py: New file with scheming_validator decorator
- ckanext/scheming/validation.py: Import unicode_safe, use ast.literal_eval
- ckanext/scheming/plugins.py: Removed six.text_type from default validators
- ckanext/scheming/unaids_validators.py: Fixed auto_create_valid_name bug
- ckanext/scheming/tests/test_form_snippets.py: Fixed Markup import
- Multiple schema JSON files: Replaced unicode with unicode_safe
- PROGRESS.md: Detailed documentation of all fixes

Test results improved significantly with these changes.
- Update GitHub Actions to latest versions (checkout@v4, setup-python@v5)
- Run tests on push and pull_request events
- Test against CKAN 2.10 and 2.11 with Python 3.10
- Simplify flake8 configuration to check only critical errors
- Remove Python 2.7 and older CKAN versions from test matrix
CKAN 2.9+ uses webassets instead of fanstatic for asset management and
Flask-based routing with different URL patterns. Updated the extension
to work with these changes:

- Migrated from fanstatic to webassets asset system
- Added webassets.yml configuration and CSS/JS assets
- Updated test helpers to use CKAN 2.10+ URL patterns and authentication
- Fixed resource URLs from /dataset/new_resource/{id} to /dataset/{id}/resource/new
- Updated authentication to use headers instead of extra_environ for CKAN 2.10+
- Added version-aware helper functions with check_ckan_version

This fixes form rendering issues and 404 errors in tests for CKAN 2.10 and 2.11.
- Updated organization and group form selectors to use correct form index in CKAN 2.11
- In CKAN 2.11, edit forms are at position [2] instead of [1] due to additional search form
- Fixed test methods to use sysadmin_env fixture and helper functions
- Fixed parameter name from 'type' to 'type_' in custom org/group tests
- All tests now pass 100% in both CKAN 2.10 and CKAN 2.11
- Add declare_config_options method in plugins.py for CKAN 2.9+ config declaration
- Add missing form snippet templates (multiple_text, number, radio, repeating_subfields)
- Add organization edit_base template
- These files support the form rendering and asset migration to CKAN 2.11
@A-Souhei A-Souhei changed the base branch from master to development December 24, 2025 15:52
@A-Souhei
Copy link
Author

A-Souhei commented Dec 24, 2025

@ChasNelson1990
This is the fork updated. Tests pass but there are more changes than in the forked upstream.
In order to decide, may be we'll need the full CKAN stack, I will do that.

Copy link
Member

@ChasNelson1990 ChasNelson1990 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants