Skip to content

Enhancements for recort import/export - #11630

Merged
SchrodingersGat merged 10 commits into
inventree:masterfrom
SchrodingersGat:import-export-metadata
Mar 30, 2026
Merged

SchrodingersGat merged 10 commits into
inventree:masterfrom
SchrodingersGat:import-export-metadata

Conversation

@SchrodingersGat

@SchrodingersGat SchrodingersGat commented Mar 30, 2026 •

Copy link
Copy Markdown
Member

This PR is the first step towards supporting sequential data import to allow migration of a setup which has plugins which have defined database models - #11235

During Export

  • Custom post-processing step adds metadata to the exported json file

During Import

  • Pre-processing step strips the metadata from the imported json file
  • Compares the compatibility of the imported data file to the currently running setup

@SchrodingersGat SchrodingersGat added this to the 1.3.0 milestone Mar 30, 2026
@SchrodingersGat SchrodingersGat added enhancement This is an suggested enhancement or new feature setup Relates to the InvenTree setup / installation process labels Mar 30, 2026
@netlify

netlify Bot commented Mar 30, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for inventree-web-pui-preview canceled.

Name Link
🔨 Latest commit 83cc3a6
🔍 Latest deploy log https://app.netlify.com/projects/inventree-web-pui-preview/deploys/69ca6fc1bdc48800085d33d2

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds metadata capture and compatibility validation to the database import/export invoke tasks to improve backup/restore reliability when plugin-provided apps/models are involved (per #11235).

Changes:

  • Add export-time metadata header (version/commit/timestamp/installed apps) to exported fixture JSON.
  • Add import-time preprocessing to strip metadata and validate compatibility (version + installed apps), with optional strict mode.
  • Introduce a list_apps Django management command and wire it into the invoke tasks and schema-generation exclusions.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
tasks.py Adds version helper functions, app listing via list_apps, export metadata injection, and import validation/flags.
src/backend/InvenTree/InvenTree/ready.py Excludes list_apps from schema-generation detection.
src/backend/InvenTree/InvenTree/management/commands/list_apps.py New management command to output installed app list in a parseable format.
Comments suppressed due to low confidence (1)

tasks.py:315

  • builtin_apps() contains a duplicate entry for 'machine' in the returned list. This can cause duplicate test targets (and redundant work) when building tested_apps. Remove the duplicate (and consider updating the docstring to clarify these are built-in apps used for testing, not the full installed app list).
def builtin_apps():
    """Returns a list of installed apps."""
    return [
        'build',
        'common',
        'company',
        'importer',
        'machine',
        'order',
        'part',
        'report',
        'stock',
        'users',
        'plugin',
        'InvenTree',
        'generic',
        'machine',
        'web',
    ]

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tasks.py Resolved
Comment thread tasks.py Resolved
Comment thread tasks.py

def installed_apps(c) -> list[str]:
"""Returns a list of all installed apps, including plugins."""
result = manage(c, 'list_apps', pty=False, hide=True)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not directly handoff the data? Going over the shell just adds failure states;
Via call_command

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Because tasks.py is not within the scope of the manage.py script, it does not operate within the correct django environment:

e.g.

def installed_apps(c) -> list[str]:
    """Returns a list of all installed apps, including plugins."""
    
    from django.core.management import call_command

    output = call_command('list_apps', stdout=subprocess.PIPE).getvalue().decode('utf-8').strip()

throws:

Traceback (most recent call last):
  File "/home/inventree/dev/venv/lib/python3.11/site-packages/django/core/management/__init__.py", line 110, in call_command
    app_name = get_commands()[command_name]
               ~~~~~~~~~~~~~~^^^^^^^^^^^^^^
KeyError: 'list_apps'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Pretty sure this will break in unexpected ways depending on the local shell environment but we will see

@codecov

codecov Bot commented Mar 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.35%. Comparing base (67d6026) to head (83cc3a6).
⚠️ Report is 389 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11630      +/-   ##
==========================================
- Coverage   91.44%   91.35%   -0.10%     
==========================================
  Files         962      962              
  Lines       49783    49836      +53     
==========================================
+ Hits        45524    45527       +3     
- Misses       4259     4309      +50     
Flag Coverage Δ
backend 89.24% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Backend Apps 91.71% <ø> (ø)
Backend General 93.40% <ø> (ø)
Frontend ∅ <ø> (∅)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@SchrodingersGat
SchrodingersGat merged commit 77744ae into inventree:master Mar 30, 2026
35 checks passed
@SchrodingersGat
SchrodingersGat deleted the import-export-metadata branch March 30, 2026 13:18
@SchrodingersGat SchrodingersGat mentioned this pull request Mar 31, 2026
3 tasks done
martonmiklos pushed a commit to martonmiklos/InvenTree that referenced this pull request Jun 30, 2026
* Add management command to list installed apps

* Add metadata to exported data file

* Validate metadata for imported file

* Update CHANGELOG.md

* Update docs

* Use internal codes

* Refactor and add more metadata

* Adjust github action workflow

* Run with --force option to setup demo dataset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement This is an suggested enhancement or new feature setup Relates to the InvenTree setup / installation process

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants