Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
22334d3
feat: update Python versions and GitHub Actions versions
ChasNelson1990 Dec 8, 2025
d790319
Initial plan
Copilot Dec 8, 2025
b8029ae
Fix Python 3.10+ compatibility and database initialization issues
Copilot Dec 8, 2025
4bea46b
Improve exception handling in tables_exist()
Copilot Dec 8, 2025
691779d
Convert test_auth.py to use pytest fixtures instead of setup()
Copilot Dec 8, 2025
9a41504
Add CKAN 2.10+ compatibility for Activity model and enable activity p…
Copilot Dec 8, 2025
7011367
Remove CKAN 2.9 support to maintain activity plugin compatibility
Copilot Dec 8, 2025
f39a3b6
Merge pull request #17 from fjelltopp/copilot/sub-pr-16
ChasNelson1990 Dec 8, 2025
c4a5eb0
Update test workflow to target CKAN 2.11 and Python 3.10
A-Souhei Jan 9, 2026
8e9c8fe
Partial CKAN 2.11 migration - incomplete due to complexity
A-Souhei Jan 9, 2026
64d0fb6
Fix CKAN 2.11 test failures: Add with_plugins and use clean_db_with_m…
A-Souhei Jan 9, 2026
c1a17ad
Fix resource version tests: Trigger activities and add user context
A-Souhei Jan 9, 2026
b7f2389
Fix 2 more test failures: Trigger activities in TestActivityActions
A-Souhei Jan 9, 2026
24b543d
Fix final test failure: Trigger activity in test_resource_version_clear
A-Souhei Jan 9, 2026
26f318c
Fix test_resource_version_create_creator_user_id_parameter
A-Souhei Jan 9, 2026
58dbef5
Fix resource_view_list bug and all intermittent test failures
A-Souhei Jan 9, 2026
348b332
Fix intermittent test failures with explicit session commits
A-Souhei Jan 9, 2026
2935363
Fix flake8 linting errors in test_actions.py
A-Souhei Jan 9, 2026
61a843d
Fix intermittent failure in TestResourceView tests
A-Souhei Jan 9, 2026
047c9fb
Untrack PROGRESS.md internal notes
A-Souhei Apr 17, 2026
815a79d
Drop CKAN <2.10 Activity import fallbacks
A-Souhei Apr 27, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 11 additions & 31 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,28 @@ on: [pull_request]
jobs:
lint:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [ 2.7, 3.9 ]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
python-version: "3.10"
- name: Install requirements
run: pip install flake8 pycodestyle
- name: Check syntax
run: |
flake8 . --count --max-line-length=127 --show-source --statistics

test:
name: CKAN
name: CKAN 2.11
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- ckan-container-version: "2.9-py2"
ckan-postgres-version: "2.9"
ckan-solr-version: "2.9-solr8"
- ckan-container-version: "2.9"
ckan-postgres-version: "2.9"
ckan-solr-version: "2.9-solr8"
- ckan-container-version: "2.10"
ckan-postgres-version: "2.10"
ckan-solr-version: "2.10"

container:
image: openknowledge/ckan-dev:${{ matrix.ckan-container-version }}
image: ckan/ckan-dev:2.11-py3.10
options: --user root
services:
solr:
image: ckan/ckan-solr:${{ matrix.ckan-solr-version }}
image: ckan/ckan-solr:2.11-solr9
postgres:
image: ckan/ckan-postgres-dev:${{ matrix.ckan-postgres-version }}
image: ckan/ckan-postgres-dev:2.11
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
Expand All @@ -57,7 +40,7 @@ jobs:
CKAN_REDIS_URL: redis://redis:6379/1

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6
- name: Install requirements
run: |
pip install -r requirements.txt
Expand All @@ -70,8 +53,5 @@ jobs:
ckan -c test.ini db init
ckan -c test.ini versions initdb
- name: Run tests
run: pytest --ckan-ini=test.ini --cov=ckanext.versions --cov-report=xml --cov-append --disable-warnings ckanext/versions/tests
- name: Upload coverage report to codecov
uses: codecov/codecov-action@v1
with:
file: ./coverage.xml
run: |
pytest --ckan-ini=test.ini --cov=ckanext.versions --disable-warnings ckanext/versions/tests/
12 changes: 6 additions & 6 deletions ckanext/versions/logic/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

from ckanext.versions.model import Version

from ckanext.activity.model import Activity

log = logging.getLogger(__name__)


Expand Down Expand Up @@ -107,9 +109,9 @@ def resource_version_create(context, data_dict):
site_id = toolkit.config.get('ckan.site_id', 'ckan_site_user')
creator_user_id = model.User.get(site_id).id

activity = model.Session.query(model.Activity). \
activity = model.Session.query(Activity). \
filter_by(object_id=resource.package_id). \
order_by(model.Activity.timestamp.desc()). \
order_by(Activity.timestamp.desc()). \
first()

if not activity:
Expand Down Expand Up @@ -446,10 +448,8 @@ def resource_view_list(up_func, context, data_dict):
'''
resource_views = up_func(context, data_dict)

versions_views = []
for i, view in enumerate(resource_views):
if view['view_type'] == 'versions_view':
versions_views.append(resource_views.pop(i))
versions_views = [view for view in resource_views if view['view_type'] == 'versions_view']
resource_views = [view for view in resource_views if view['view_type'] != 'versions_view']

resource_views.extend(versions_views)

Expand Down
8 changes: 5 additions & 3 deletions ckanext/versions/logic/dataset_version_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from ckanext.versions.logic.action import version_show
from ckanext.versions.model import Version

from ckanext.activity.model import Activity

log = logging.getLogger(__name__)


Expand Down Expand Up @@ -48,11 +50,11 @@ def dataset_version_create(context, data_dict):
creator_user_id = context['auth_user_obj'].id

if activity_id:
activity = model.Activity.get(activity_id)
activity = Activity.get(activity_id)
else:
activity = model.Session.query(model.Activity). \
activity = model.Session.query(Activity). \
filter_by(object_id=dataset_id). \
order_by(model.Activity.timestamp.desc()). \
order_by(Activity.timestamp.desc()). \
first()
if not activity:
raise toolkit.ObjectNotFound('Activity not found')
Expand Down
12 changes: 10 additions & 2 deletions ckanext/versions/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,16 @@ def as_dict(self):


def create_tables():
Version.__table__.create()
from ckan.model import meta
Version.__table__.create(bind=meta.engine, checkfirst=True)


def tables_exist():
return Version.__table__.exists()
from ckan.model import meta
try:
engine = meta.engine
if engine is None:
return False
return Version.__table__.exists(bind=engine)
except (AttributeError, TypeError):
return False
2 changes: 1 addition & 1 deletion ckanext/versions/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def get_auth_functions(self):
'version_delete': auth.version_delete,
'version_list': auth.version_list,
'version_show': auth.version_show,
'resource_version_clear': action.resource_version_clear,
'resource_version_clear': auth.resource_version_clear,
}

# ITemplateHelpers
Expand Down
18 changes: 18 additions & 0 deletions ckanext/versions/tests/fixtures.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

from ckan import model
from ckan.tests import factories
from ckanext.versions.tests import create_version, versions_db_setup

Expand All @@ -9,6 +10,23 @@ def versions_setup():
versions_db_setup()


@pytest.fixture
def clean_db_with_migrations(clean_db):
"""
Extends clean_db fixture to add CKAN 2.11 activity plugin schema.

The activity plugin in CKAN 2.11 requires a permission_labels column
in the activity table. This fixture ensures the column exists after
clean_db resets the database.
"""
# After clean_db runs, add the permission_labels column
connection = model.Session.connection()
connection.execute(
"ALTER TABLE activity ADD COLUMN IF NOT EXISTS permission_labels text[];"
Comment thread
A-Souhei marked this conversation as resolved.
)
model.Session.commit()


@pytest.fixture()
def org_admin():
return factories.User(name="admin")
Expand Down
Loading