fix: yaegi plugins cannot import xorm or xormigrate - #3549
Merged
Conversation
The plugin docs tell plugins to implement Migrations() returning []*xormigrate.Migration, but neither `xorm.io/xorm` nor `src.techknowlogick.com/xormigrate` was in the yaegi symbol table, so an interpreted plugin failed at the import before it could ever be loaded. Add both packages to yaegiSymbolPackages and commit the generated symbol tables, plus a loader test that runs an interpreted plugin migration against a real engine. Fixes #3501
Preview DeploymentPreview deployments for this PR are available at:
The preview environment will start automatically on first visit. Subsequent pushes to this PR will update the Run locally with Dockerdocker pull ghcr.io/go-vikunja/vikunja:pr-3549
docker run -p 3456:3456 ghcr.io/go-vikunja/vikunja:pr-3549Last updated for commit ef2c983 |
1 task
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.
Plugin docs tell plugins to implement
Migrations() []*xormigrate.Migration, but neitherxorm.io/xormnorsrc.techknowlogick.com/xormigratewas registered in yaegi symbol table, so interpreted plugin died at import before loading:Cause:
yaegiSymbolPackagesinmagefile.go— listmage generate:yaegi-symbolsextracts — omitted both packages. Same shape as #3500 / #3502.Fixes #3501
Now:
xormigrateandxormadded toyaegiSymbolPackages; generatedxormigrate.goandxorm.gocommitted.pkg/plugins/yaegi/migrations_test.goloads interpreted plugin fromtestdata/migrationplugin, then runs itsMigrateFuncagainst real sqlite engine and asserts table exists — covers import resolution and interpreted-func-over-*xorm.Engineboundary.Gotcha for plugin authors
Interpreted types reach xorm as anonymous
reflectstructs with no methods, so aTableName()method on a plugin struct is invisible andtx.Sync2(new(PluginData))producesnear "(": syntax error(empty table name). Plugin migrations must name the table explicitly:tx.Table("plugin_data").Sync2(&PluginData{}). The docs example on vikunja.io uses theSync2(new(...))form and should be updated — docs are not in this repo, so that is not part of this PR.How to verify
Enable the yaegi loader in
config.yml(plugins.enabled: true,plugins.loader: yaegi).Drop the repro plugin from yaegi plugins cannot implement migrations:
xormandxormigrateare not exposed in the symbol table #3501 into the plugin directory, changing its migration body to name the table explicitly:Start the API.
Expected: the log shows the plugin loading successfully and the migration running; the
reprotable exists in the database.Before this PR: startup logs
Failed to load yaegi plugin ...: unable to find source related to: "src.techknowlogick.com/xormigrate"and the plugin never loads.