Potential Bug 9.0

Saturday, 3 November 2018 · 2 messages · last reply 5 Nov 2018
DZ
Dieter Zanzinger3 Nov 2018 16:39 #
Dear BaseX-Team, I encountered some unexpected behavour, maybe a bug? I declare a collection of function-signatures. Then I iterate over the collection inside a copy/modify-construct. Each function adds a node to the database. This works as expected:
declare variable $_:abschlussqueries := (_:f1#2 , _:f2#2);

declare %updating
     %rest:path('treez/ab4')
function _:abschluss4() as element() {
    <Postabschluss>{ (

        try{
                let $db := doc('FGfax')/Dateien/Datei
                for $d in $db
                return (

                        copy $c := $d
                        modify (
                            for $funct at $counter in $_:abschlussqueries
                            return (
                                (: prof:dump("bla: " || $counter) , :)
                                prof:void(""),
                                $funct($c, $counter)
                            )
                        )
                        return (
                            $c
                        )
                )

        } catch * {
                let $db := doc('FGfax')/Dateien
                return
                        error(xs:QName("dieter:norights10"), "Error: "|| $err:code || ': ' || $err:description , 418 )
        }

    ) }</Postabschluss>
};

declare %updating function _:f1($c, $counter )  {

            try {(
                filepath:copy-to("C:\Users\Win7ProUser\Documents\FGscan_ScanDocs\bla.xml","C:\Users\Win7ProUser\Documents\FGscan_ScanDocs\bla1.xml"),
                insert node <f1>function1 </f1> as last into $c
            )} catch * {
                insert node <f1>{"Error: "|| $err:code || ': ' || $err:description}</f1> as last into $c
            }
};

declare %updating function _:f2($c, $counter )  {

            try {(
                filepath:copy-to("C:\Users\Win7ProUser\Documents\FGscan_ScanDocs\bla.xml","C:\Users\Win7ProUser\Documents\FGscan_ScanDocs\bla1.xml"),
                insert node <f2>function2 </f2> as last into $c
            )} catch * {
                insert node <f2>{"Error: "|| $err:code || ': ' || $err:description}</f2> as last into $c
            }
};
————————————— Result:
<?xml version="1.0" encoding="ISO-8859-1"?>
<Postabschluss>
 <>
<Datei uuid="8ad03f50-4b9c-461a-b818-1a97dc5735e9">
 <>
<sortedPath znen=""> <> at SMB10.211.55.6/netzlaufwerktestF/sortierter_Posteingang/OHNE/#Fax_OHNE_AZ--201803061002-154925-00498171251x1800.pdf</sortedPath>
<f1> <>function1 </f1>
<f2> <>function2 </f2>
</Datei>
<Datei uuid="26a3aee7-a0d8-4b8d-acd4-90554c8ab28c">
 <>
<sortedPath znen=""> <> at SMB10.211.55.6/netzlaufwerktestF/sortierter_Posteingang/OHNE/#Fax_OHNE_AZ--201803061003-154928-0049242344x1801.pdf</sortedPath>
<f1> <>function1 </f1>
<f2> <>function2 </f2>
</Datei>
<Datei uuid="af0548aa-08cf-464a-839d-421363f452ce">
 <>
<sortedPath znen=""> <> at SMB10.211.55.6/netzlaufwerktestF/sortierter_Posteingang/OHNE/#Fax_OHNE_AZ--201803061220-154966-004999429025.pdf</sortedPath>
<f1> <>function1 </f1>
<f2> <>function2 </f2>
</Datei>
——————
But if remove the line: prof:void("“), the result is:
<?xml version="1.0" encoding="ISO-8859-1"?>
<Postabschluss>
 <>
<Datei uuid="8ad03f50-4b9c-461a-b818-1a97dc5735e9">
 <>
<sortedPath znen=""> <> at SMB10.211.55.6/netzlaufwerktestF/sortierter_Posteingang/OHNE/#Fax_OHNE_AZ--201803061002-154925-00498171251x1800.pdf</sortedPath>
</Datei>
<Datei uuid="26a3aee7-a0d8-4b8d-acd4-90554c8ab28c">
 <>
<sortedPath znen=""> <> at SMB10.211.55.6/netzlaufwerktestF/sortierter_Posteingang/OHNE/#Fax_OHNE_AZ--201803061003-154928-0049242344x1801.pdf</sortedPath>
</Datei>
<Datei uuid="af0548aa-08cf-464a-839d-421363f452ce">
 <>
<sortedPath znen=""> <> at SMB10.211.55.6/netzlaufwerktestF/sortierter_Posteingang/OHNE/#Fax_OHNE_AZ--201803061220-154966-004999429025.pdf</sortedPath>
</Datei>
</Postabschluss>
Do you have any explanation for this behavour? Some other updating expression instead of prof:void(„“) works as well. But if my only call is to the functions, it does not work. Sincerely Dieter Zanzinger
CG
Christian Grün5 Nov 2018 18:21 #
Thanks for the bug report! In your example code, I have additionally prefixed the function call with the 'updating' keyword (otherwise, it won’t be detected as updating expression), and the return type of the RESTXQ function had to replaced with empty-sequence(). As the updating return clause returns an empty sequence, the full FLWOR expression was optimized away – which was obviously wrong, due to the side-effecting nature of the update function. If prof:void('') is added, the code was preserved because this function was detected as a non-deterministic function. With the latest snapshot, I am now checking for both updating and non-deterministic expressions [1,2]. Until BaseX 9.1.1 will be released, it will be a good escape to additionally call prof:void(''). Hope this helps Christian [1] https://github.com/BaseXdb/basex/issues/1636 [2] http://files.basex.org/releases/latest/
Quoted text · Dieter Zanzinger · 118 lines
On Sat, Nov 3, 2018 at 4:39 PM Dieter Zanzinger <dieter.zanzinger at icloud.com> wrote: > > Dear BaseX-Team, > > I encountered some unexpected behavour, maybe a bug? > > I declare a collection of function-signatures. > Then I iterate over the collection inside a copy/modify-construct. Each function adds a node to the database. > > This works as expected: > > declare variable $_:abschlussqueries := (_:f1#2 , _:f2#2); > > declare %updating > %rest:path('treez/ab4') > function _:abschluss4() as element() { > <Postabschluss>{ ( > > try{ > let $db := doc('FGfax')/Dateien/Datei > for $d in $db > return ( > > copy $c := $d > modify ( > for $funct at $counter in $_:abschlussqueries > return ( > (: prof:dump("bla: " || $counter) , :) > prof:void(""), > $funct($c, $counter) > ) > ) > return ( > $c > ) > ) > > } catch * { > let $db := doc('FGfax')/Dateien > return > error(xs:QName("dieter:norights10"), "Error: "|| $err:code || ': ' || $err:description , 418 ) > } > > ) }</Postabschluss> > }; > > declare %updating function _:f1($c, $counter ) { > > try {( > filepath:copy-to("C:\Users\Win7ProUser\Documents\FGscan_ScanDocs\bla.xml","C:\Users\Win7ProUser\Documents\FGscan_ScanDocs\bla1.xml"), > insert node <f1>function1 </f1> as last into $c > )} catch * { > insert node <f1>{"Error: "|| $err:code || ': ' || $err:description}</f1> as last into $c > } > }; > > declare %updating function _:f2($c, $counter ) { > > try {( > filepath:copy-to("C:\Users\Win7ProUser\Documents\FGscan_ScanDocs\bla.xml","C:\Users\Win7ProUser\Documents\FGscan_ScanDocs\bla1.xml"), > insert node <f2>function2 </f2> as last into $c > )} catch * { > insert node <f2>{"Error: "|| $err:code || ': ' || $err:description}</f2> as last into $c > } > }; > > > ————————————— > Result: > > <?xml version="1.0" encoding="ISO-8859-1"?> > <Postabschluss> > <Datei uuid="8ad03f50-4b9c-461a-b818-1a97dc5735e9"> > <sortedPath znen=""> at SMB10.211.55.6/netzlaufwerktestF/sortierter_Posteingang/OHNE/#Fax_OHNE_AZ--201803061002-154925-00498171251x1800.pdf</sortedPath> > <f1>function1 </f1> > <f2>function2 </f2> > </Datei> > <Datei uuid="26a3aee7-a0d8-4b8d-acd4-90554c8ab28c"> > <sortedPath znen=""> at SMB10.211.55.6/netzlaufwerktestF/sortierter_Posteingang/OHNE/#Fax_OHNE_AZ--201803061003-154928-0049242344x1801.pdf</sortedPath> > <f1>function1 </f1> > <f2>function2 </f2> > </Datei> > <Datei uuid="af0548aa-08cf-464a-839d-421363f452ce"> > <sortedPath znen=""> at SMB10.211.55.6/netzlaufwerktestF/sortierter_Posteingang/OHNE/#Fax_OHNE_AZ--201803061220-154966-004999429025.pdf</sortedPath> > <f1>function1 </f1> > <f2>function2 </f2> > </Datei> > —————— > > > But if remove the line: prof:void("“),the result is: > > <?xml version="1.0" encoding="ISO-8859-1"?> > > <Postabschluss> > > <Datei uuid="8ad03f50-4b9c-461a-b818-1a97dc5735e9"> > > <sortedPath znen=""> at SMB10.211.55.6/netzlaufwerktestF/sortierter_Posteingang/OHNE/#Fax_OHNE_AZ--201803061002-154925-00498171251x1800.pdf</sortedPath></Datei> > > <Datei uuid="26a3aee7-a0d8-4b8d-acd4-90554c8ab28c"> > > <sortedPath znen=""> at SMB10.211.55.6/netzlaufwerktestF/sortierter_Posteingang/OHNE/#Fax_OHNE_AZ--201803061003-154928-0049242344x1801.pdf</sortedPath> > > </Datei> > > <Datei uuid="af0548aa-08cf-464a-839d-421363f452ce"> > > <sortedPath znen=""> at SMB10.211.55.6/netzlaufwerktestF/sortierter_Posteingang/OHNE/#Fax_OHNE_AZ--201803061220-154966-004999429025.pdf</sortedPath> > > </Datei> > > </Postabschluss> > > > Do you have any explanation for this behavour?Some other updating expression instead of prof:void(„“) works as well. But if my only call is to the functions, it does not work. > SincerelyDieter Zanzinger

⚡Generated with XQuery