Skip to content

Fix api/v1/projects?languages=X query which failed with DB error#1581

Open
bpfoley wants to merge 1 commit into
DistributedProofreaders:masterfrom
bpfoley:api-languages-fix
Open

Fix api/v1/projects?languages=X query which failed with DB error#1581
bpfoley wants to merge 1 commit into
DistributedProofreaders:masterfrom
bpfoley:api-languages-fix

Conversation

@bpfoley
Copy link
Copy Markdown
Collaborator

@bpfoley bpfoley commented May 13, 2026

No description provided.

@bpfoley
Copy link
Copy Markdown
Collaborator Author

bpfoley commented May 13, 2026

Reproducer to find a project with English as the primary language. Fails without this patch

  #!/bin/bash
  set -euxo pipefail

  API_KEY=bfoley
  ROOT=https://www.pgdp.org/~bfoley/c.branch/api-languages-fix

  curl -X GET "$ROOT/api/v1/projects?per_page=1&languages=English+with" \
      -H "Accept: application/json" \
      -H "X-API-KEY: $API_KEY"

Comment thread api/v1_projects.inc
Comment on lines -74 to +79
if (in_array($field, ["author", "title", "languages", "clearance"])) {
// Languages occur as one language or two and are stored as
// "Lang1" or "Lang1 with Lang2" in projects.language.
// See Project.inc:encode_languages
if ($field == "languages") {
$likes_str = surround_and_join($values, "language LIKE '%", "%'", ' OR ');
$where .= " AND ($likes_str)";
} elseif (in_array($field, ["author", "title", "clearance"])) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It took me way to long to spot the difference here, this might be more straightforward:

// The API exposes "languages" but the table column is "language" and
// are stored as "Lang1" or "Lang1 with Lang2".
// See Project.inc:encode_languages
if ($field == "languages") {
    $column_name = "language";
}

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

Successfully merging this pull request may close these issues.

2 participants