Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow module imports in one-off xqueries #5529

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

line-o
Copy link
Member

@line-o line-o commented Oct 31, 2024

Description:

  • add modified conf.xml ModuleImport tests
  • add tests for one-off queries with module imports
    • using a modified conf.xml that loads functx into package repo via auto deploy
    • of a registered module without location hint
    • of a module with location hint
  • change XQueryContext to allow imports again
  • change SourceFactory to work with contextPath set to "."

Reference:

fixes #5525
fixes #5530

Type of tests:

Java tests added in src/test/java/org/exist/xquery/ModuleImportTest.java

@@ -111,7 +111,7 @@ public class SourceFactory {
&& ((location.startsWith("/db") && !Files.exists(Paths.get(firstPathSegment(location))))
|| (contextPath != null && contextPath.startsWith("/db") && !Files.exists(Paths.get(firstPathSegment(contextPath)))))) {
final XmldbURI pathUri;
if (contextPath == null) {
if (contextPath == null || ".".equals(contextPath)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't want to upset anyone, but I just wanted to point out that this is the wrong approach to fixing this issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is fixing an additional bug I found while creating tests:

see importLibraryFromDbLocation and importLibraryFromXMLDBLocation

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I understood that, but it still is the wrong approach.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I understood that, but it still is the wrong approach.

@adamretter Could you explain why you think this is the wrong approach and how do you think it should be solved correctly?

@line-o
Copy link
Member Author

line-o commented Oct 31, 2024

Adding the functx library to auto deploy in the conf.xml used for all tests leads to test failures.
There are, however, other configurations that do have functx loaded, see src/test/resources-filtered/org/exist/xquery/functions/transform/conf.xml.

Should I, either

  1. limit the application of the conf.xml with functx to only xquery tests
  2. limit the application of the conf.xml with functx to only moduleImport tests
  3. try to import other modules that are present without adding functx

@joewiz
Copy link
Member

joewiz commented Oct 31, 2024

If the issue isn't functx-specific, then choice 3 sounds like it would address the issue.

@adamretter
Copy link
Contributor

You should not have to modify conf.xml for this.

@line-o
Copy link
Member Author

line-o commented Nov 1, 2024

@joewiz module imports are certainly not functx specific.

@line-o
Copy link
Member Author

line-o commented Nov 1, 2024

I ended up using option 2, only use conf.xml with functx loaded via autodeploy for ModuleImportTest.

For the tests to work we need do need to add a pure library package to exist. It just happens that the functx-1.0.1.xar is already part of the test fixtures in
src/test/resources/functx/functx-1.0.1.xar.
With that we have a library module that can be imported with and without location hint.

So far as I can see there is no other way than to add another configuration with functx added to autodeploy.
We could change both src/test/java/org/exist/xquery/functions/transform/TransformFromPkgTest.java and src/test/java/org/exist/xquery/ModuleImportTest.java test classes to both use a conf-with-functx.xml to make its use-case more obvious and also re-usable.

@line-o line-o changed the title [bugfix] allow module imports in one-off xqueries Allow module imports in one-off xqueries Nov 5, 2024
fixes eXist-db#5525
fixes eXist-db#5530

- add functx to autodeploy for xquery tests
- add tests for one-off queries with module imports
  - of a registered module without location hint
  - of a module with location hint
- change XQueryContext to allow imports again
- change SourceFactory to work with contextPath set to "."
Copy link

sonarcloud bot commented Nov 19, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
66.7% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In review
Development

Successfully merging this pull request may close these issues.

[BUG] one-off queries cannot import modules with location hint [BUG] 'other' is different type of Path
5 participants