-
-
Notifications
You must be signed in to change notification settings - Fork 179
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
[BUG] Variable declaration in library module is not processed reliably #5103
Comments
@djbpitt I took a quick look at this, I note that it is using the XQuery URL Rewrite facility to forward requests for the URI The XQuery URL Rewrite facility is a big part of what is in your repository, I wonder if we can narrow down the problem... if you don't use the rewriting but instead directly access
|
@djbpitt Not related to the issue you are reporting, but I have an observation on how you have structured your code and the ability to reuse your code. I might offer some advice... This block in declare variable $re:genres as element(genre)+ :=
doc(concat(
request:get-attribute("$exist:root"),
request:get-attribute("$exist:controller"),
"/aux/genres.xml"
))/descendant::genre;
declare function re:bgMsName($ms as element(tei:TEI)) as xs:string {
... That should be avoided as it limits reuse and pollutes your code with the mechanisms employed by XQuery URL Rewrite (which really you should not have to worry about here). If I understand correctly, you are trying to locate the data within your app package for use by your query?
Even once I have the declare function re:bgMsName($data-collection-path as xs:string, $ms as element(tei:TEI)) as xs:string {
... or another second option: declare function $re:genres-data($data-collection-path as xs:string) as element(genre)+ {
fn:doc($data-collection-path as xs:string || "/aux/genres.xml")/descendant::genre
}
declare function re:bgMsName($genres as element(genre)+, $ms as element(tei:TEI)) as xs:string {
... The advantage of this second option is that |
@adamretter Thank you for your generous interest and suggestions! I'll respond to the more general suggestions separately, but with respect to your question about possible interference from URL rewriting, I've pushed an update that does the following:
The original issue (variable is not defined on first call, but is available subsequently) happens with and without URL rewriting. |
@adamretter I've now had a chance to read your suggestions about reducing my reliance on controller variables for locating resources, and I understand and appreciate the advantages of doing that. Thank you for the advice! The comments below are not your problem, to be sure, but in case they’re of any interest: I understand the virtue, in the second method, of decoupling the function from dependence on the context. I don't, though, understand what Meanwhile (and also not your problem), the first method is not within my abilities. I have no knowledge of build tools beyond the ability to type |
@djbpitt Through a process of trial-and-error I have eliminated almost everything that is superfluous to causing your issue. I believe the issue is triggered through the use of |
Thanks, @adamretter . I just merged your PR. |
It returns the database path to the XQuery Module that is currently being executed, i.e. the caller of that function.
In this instance, because the query you are executing from eXide is submitted to the server as a string and is not persisted in the database, there is no meaningful path that can be returned, so eXide is showing you something silly. |
@adamretter Got it! I'll explore further … |
Java21....? |
Describe the bug
A clear and concise description of what the bug is.
The bug is reproducible in https://github.com/djbpitt/exist-import-test. Clone the repo, build, install, and load the index page in a browser. When you click on a link, the browser reports:
If you reload the page it responds correctly, and continues to do so. That is, the error is raised only the first time you try to use the resource. If you stop and restart eXist-db, the error will again appear on first use of the resource.
Expected behavior
A clear and concise description of what you expected to happen.
I expect the link to load the target result correctly on first access, and not only on subsequent access, as it does now.
Context (please always complete the following information)
I see the same behavior on my Centos 7 server. @line-o was able to reproduce the behavior with the current (as of 2023-10-28) development version of eXist-db.
Additional context
How is eXist-db installed?
Any custom changes in e.g.
conf.xml
?Additional information
$re:genres
with alet
statement inside the function that uses that variable, there is no error. This is a workaround, rather than a solution, because 1) the variable should be available when declared in the prologue, and not only when declared in alet
statement, and 2) in Real Life I use the same variable in more than one function, so declaring it in the prologue is DRYer than declaring it separately in each function that uses it.util:log("info", $re:genres),
to the function body weirdly does fix the issue on first request. A heisen-bug, the moment you debug it it is gone."The text was updated successfully, but these errors were encountered: