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

Missing results from CSW Transactional (update) requests #678

Open
felnne opened this issue Apr 20, 2020 · 0 comments
Open

Missing results from CSW Transactional (update) requests #678

felnne opened this issue Apr 20, 2020 · 0 comments

Comments

@felnne
Copy link

felnne commented Apr 20, 2020

Hi,

I am having problems using OWSLib with a CSW Transactional (update) request.

The operation itself is successful [1] but the the csw.results attribute is None instead of the operation results.

I tracked this down to the _parsetransactionsummary method, which is unable to parse the transaction summary element correctly because the ElementPath query doesn't match.

I think this can be fixed by searching for the transaction summary element anywhere in the document, rather than explicitly from the root element i.e:

Replace:

def _parsetransactionsummary(self):
    val = self._exml.find(util.nspath_eval('csw:TransactionResponse/csw:TransactionSummary', namespaces))

With:

def _parsetransactionsummary(self):
    val = self._exml.find(f".//{util.nspath_eval('csw:TransactionSummary', namespaces)}")

Given the csw:TransactionSummary element is only used in a csw:TransactionalResponse (and we check for the possible presense of that element before this code is reached, as well as checking for an exception) I felt it would be okay to use a less precise query. I used an F string because the Travis tests only specified Python 3.6 or higher.

However if that isn't acceptable, this XPath can be used instead to find the element:

def _parsetransactionsummary(self):
    val = self._exml.xpath('/csw:TransactionResponse/csw:TransactionSummary', namespaces=namespaces)

Reviewing the tests, I couldn't see anything for transactional support so I'm wondering if this has been silently failing up to now, or if this just affects me.

If it's general, and one of the solutions above is acceptable, I'm happy make a pull-request for it, and possibly a test if I can.

Thanks for the all the work on this library, it's already saved me days work, this is a final snag for my use-case.

As a workaround for this I'm using this code:

csw = CatalogueServiceWeb(app.config["CSW_ENDPOINT"])
csw.transaction(ttype="update", typename="gmd:MD_Metadata", record=document)
csw.results["updated"] = ElementTree(fromstring(csw.response)).xpath("/csw:TransactionResponse/csw:TransactionSummary/csw:totalUpdated/text()", namespaces=csw_namespaces)[0]

[1] Example successful CSW response (given by etree.tostring(self._exml)):

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- pycsw 2.4.2 -->
<csw:TransactionResponse xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dct="http://purl.org/dc/terms/" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gml="http://www.opengis.net/gml" xmlns:ows="http://www.opengis.net/ows" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0.2" xsi:schemaLocation="http://www.opengis.net/cat/csw/2.0.2 http://schemas.opengis.net/csw/2.0.2/CSW-publication.xsd">
    <csw:TransactionSummary>
        <csw:totalInserted>0</csw:totalInserted>
        <csw:totalUpdated>1</csw:totalUpdated>
        <csw:totalDeleted>0</csw:totalDeleted>
    </csw:TransactionSummary>
</csw:TransactionResponse>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant