[bug] Fix for data import (#13367)

* [bug] Fix for data import

Correctly skip plugin records (if requested) when importing data

* Fix for data export

* Updated CI workflow
This commit is contained in:
Oliver authored and GitHub committed 2026-11-25 20:31:33 +11:00
1 parent 65a8113baf
commit 5d24a3f327
5 files changed
+298 -14

No files matched your search

+115
View File
@@ -59,6 +59,7 @@ jobs:
- .github/workflows/import_export.yaml
- .github/scripts/check_exported_data.py
- .github/scripts/seed_content_excludes_data.py
- .github/scripts/check_imported_data.py
- 'src/backend/**'
- 'tasks.py'
import-export:
@@ -190,6 +191,120 @@ jobs:
--check-email exclude --check-tokens exclude --check-sso exclude \
--check-session exclude --check-permissions exclude
exclude-plugins:
# Ensure that --exclude-plugins works for both export and import, with
# and without --bulk:
# - Export: no plugin.* records, no plugin app (AppMixin) records, and the
# plugin app is not listed in the metadata installed_apps
# - Import: a *full* dataset (including plugin app records) can be imported
# with --exclude-plugins into a target where the plugin is not installed,
# without needing --ignore-nonexistent
runs-on: ubuntu-latest
needs: paths-filter
if: needs.paths-filter.outputs.server == 'true' || contains(github.event.pull_request.labels.*.name, 'full-run')
env:
FULL_FILE: /home/runner/work/InvenTree/test_inventree_data_full.json
EXCLUDED_FILE: /home/runner/work/InvenTree/test_inventree_data_excluded.json
EXCLUDED_BULK_FILE: /home/runner/work/InvenTree/test_inventree_data_excluded_bulk.json
EXCLUDED_SUMMARY: /home/runner/work/InvenTree/test_inventree_summary_excluded.json
EXCLUDED_BULK_SUMMARY: /home/runner/work/InvenTree/test_inventree_summary_excluded_bulk.json
services:
postgres:
image: postgres:17
env:
POSTGRES_USER: inventree
POSTGRES_PASSWORD: password
ports:
- 5432:5432
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Environment Setup
uses: $/.github/actions/setup
with:
apt-dependency: gettext poppler-utils libpq-dev
pip-dependency: psycopg
update: true
static: false
- name: Setup Postgres Database
run: |
invoke migrate
invoke dev.setup-test -i
- name: Create Plugin Data
run: |
pip install --only-binary :all: -U inventree-dummy-app-plugin==0.1.0
invoke migrate
cd src/backend/InvenTree && python manage.py create_dummy_data
- name: Export Full Dataset (plugin data included)
run: |
invoke export-records -o -f ${{ env.FULL_FILE }}
python .github/scripts/check_exported_data.py ${{ env.FULL_FILE }}
- name: Export With --exclude-plugins
run: |
invoke export-records -o -f ${{ env.EXCLUDED_FILE }} --exclude-plugins --summary ${{ env.EXCLUDED_SUMMARY }}
python .github/scripts/check_exported_data.py ${{ env.EXCLUDED_FILE }} --exclude-plugins
- name: Bulk Export With --exclude-plugins
run: |
invoke export-records -o -f ${{ env.EXCLUDED_BULK_FILE }} --exclude-plugins --bulk --summary ${{ env.EXCLUDED_BULK_SUMMARY }}
python .github/scripts/check_exported_data.py ${{ env.EXCLUDED_BULK_FILE }} --exclude-plugins
- name: Compare Standard and Bulk Exports
run: |
# The bulk export must contain exactly the same records as the standard export
python - <<'EOF'
import json, sys
plain = json.load(open('${{ env.EXCLUDED_SUMMARY }}'))
bulk = json.load(open('${{ env.EXCLUDED_BULK_SUMMARY }}'))
if plain['records'] != bulk['records']:
keys = set(plain['records']) | set(bulk['records'])
for key in sorted(keys):
a, b = plain['records'].get(key, 0), bulk['records'].get(key, 0)
if a != b:
print(f'- {key}: standard={a}, bulk={b}')
print('ERROR: Standard and bulk exports (--exclude-plugins) contain different records')
sys.exit(1)
if plain['metadata']['installed_apps'] != bulk['metadata']['installed_apps']:
print('ERROR: Standard and bulk exports (--exclude-plugins) list different installed apps')
sys.exit(1)
print(f"Confirmed standard and bulk exports match ({plain['total_records']} records)")
EOF
- name: Uninstall Plugin
run: |
pip uninstall -y inventree-dummy-app-plugin
- name: Update Environment Variables for Sqlite
run: |
echo "INVENTREE_DB_ENGINE=sqlite" >> $GITHUB_ENV
echo "INVENTREE_DB_NAME=/home/runner/work/InvenTree/test_inventree_db.sqlite3" >> $GITHUB_ENV
- name: Setup Sqlite Database (plugin not installed)
run: |
invoke migrate
test -f /home/runner/work/InvenTree/test_inventree_db.sqlite3 || (echo "Sqlite database not created" && exit 1)
- name: Import Excluded Dataset
run: |
# Plugin apps are not listed in the metadata, so --strict must pass
invoke import-records -c -f ${{ env.EXCLUDED_FILE }} --strict --exclude-plugins
cd src/backend/InvenTree && python ../../../.github/scripts/check_imported_data.py
- name: Bulk Import Excluded Dataset
run: |
invoke import-records -c -f ${{ env.EXCLUDED_BULK_FILE }} --strict --exclude-plugins --bulk
cd src/backend/InvenTree && python ../../../.github/scripts/check_imported_data.py
- name: Import Full Dataset With --exclude-plugins
run: |
# The full dataset contains plugin app records - these must be skipped
# by --exclude-plugins, *without* needing --ignore-nonexistent.
# Note: --strict is not used, as the source metadata lists the plugin app
invoke import-records -c -f ${{ env.FULL_FILE }} --exclude-plugins
cd src/backend/InvenTree && python ../../../.github/scripts/check_imported_data.py
- name: Bulk Import Full Dataset With --exclude-plugins
run: |
invoke import-records -c -f ${{ env.FULL_FILE }} --exclude-plugins --bulk
cd src/backend/InvenTree && python ../../../.github/scripts/check_imported_data.py
plugin-absent:
# Ensure that importing data referencing a plugin's own models degrades
# gracefully (skipping just those records) when that plugin isn't