Skip to content

Filtering on a value containing an apostrophe fails (HTTP 400) #59

Description

@lefranz

Thanks for swissparlpy — we use it daily to poll Curia Vista for a Swiss financial-crime news watch, and 2.0 upgraded cleanly for us.

Reporting this here because it hits swissparlpy users even though the fix belongs upstream.

Symptom

import swissparlpy as spp
spp.get_data("Business", Language="FR", Title="délit d'initié")
# swissparlpy.errors.SwissParlError: The server returned a HTTP error

The generated query is:

$filter=Language eq 'FR' and Title eq 'délit d'initié'
→ HTTP 400  "Syntax error at position 45 in 'Language eq 'FR' and Title eq 'délit d'initié''."

Cause

pyodata's EdmStringTypTraits.to_literal() wraps the value in single quotes without doubling quotes inside it, so the literal terminates at the apostrophe. This affects the keyword-argument and spp.Filter paths — anything where pyodata builds the literal from a Python value. It is not a swissparlpy bug, but it bites French and Italian queries hard (l'Etat, d'initié, dell'), which is a lot of what this library is used for.

I have opened a PR upstream: SAP/python-pyodata#313. Verified against ws.parlament.ch — the same call returns HTTP 200 with the patch.

Possible action here, once upstream ships

  1. Raise the floor to the pyodata release containing the fix (currently pyodata>=1.11.1).
  2. Independently of that: the raw-string path is passthrough — get_data(..., filter="substringof('délit d''initié',Title)") goes straight to pyodata.filter() untouched, so escaping is the caller's job there and always will be. A line in the README, or a small exported helper (swissparlpy.escape_string()), would save the next person the 400. We carry a three-line local helper for exactly this.

Happy to send a PR for either if useful — just say which shape you would prefer.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions