JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

PG::SyntaxError with Apartment gem

Offen
#1,316 6 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Ruby
Sterne
2.3k
Forks
546
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

This issue is a (choose one):

  • Problem/bug report.
  • Feature request.
  • Request for support. Note: Please try to avoid submitting issues for support requests. Use Gitter instead.

Checklist before submitting:

  • I've searched for an existing issue.
  • I've asked my question on Gitter and have not received a satisfactory answer.
  • I've included a complete bug report template. This step helps us and allows us to see the bug without trying to reproduce the problem from your description. It helps you because you will frequently detect if it's a problem specific to your project.
  • The feature I'm asking for is compliant with the JSON:API spec.

Description

  • Ruby 2.5.5
  • Rails 5.2
  • jsonapi-resources 0.10.2
Bug reports:

When using Apartment (multi-tenancy gem), any model that is shared among all tenants (i.e. in the 'public' schema) return an error 500 (PG::SyntaxError) when trying to query the API. This issue only happens with shared models, and not with tenant-specific models. The issue lies in the way jsonapi-resources writes its queries, e.g:

Internal Server Error: PG::SyntaxError: ERROR:  syntax error at or near "."
LINE 1: SELECT public.accounts.id AS public.accounts_id FROM "public...

The whole query is:

SELECT public.accounts.id AS public.accounts_id FROM "public"."accounts" WHERE "public"."accounts" = $1

SELECT public.accounts.id AS public.accounts_id FROM "public"."accounts" WHERE "public"."accounts" = $1

The bold part is the issue. There should be no dot in the AS statement. public.accounts_id should be public_accounts_id or just accounts_id.

This should be a trivial fix, but I just don't know where in the gem code queries are generated.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Es ist keine Quelldatei und kein Test angegeben. Beginne damit, die Apartment-Abfrage für shared models mit den aufgeführten Ruby-, Rails- und jsonapi-resources-Versionen zu reproduzieren, und verfolge dann die Abfragegenerierung, die das gezeigte SELECT erzeugt. Als abgeschlossen gilt die Aufgabe, wenn der generierte Alias keinen Punkt mehr enthält und die API-Abfrage für das shared model erfolgreich ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
postgresql, rails, ruby
Bereich
api, database
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.