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

Context does not work with Postgres with regular json fields #102

Open
djfpaagman opened this issue Nov 21, 2024 · 0 comments
Open

Context does not work with Postgres with regular json fields #102

djfpaagman opened this issue Nov 21, 2024 · 0 comments

Comments

@djfpaagman
Copy link
Contributor

Currently when you try to set something in the context with PG you will get the following error:

PG::UndefinedFunction: ERROR: operator does not exist: json = json LINE 1: ...pdated_at=(CASE WHEN ("acidic_job_values"."value" IS NOT DIS... ^ HINT: No operator matches the given name and argument types. You might need to add explicit type casts.

it seems Postgres cannot compare json values directly, as it needs to do that for the upsert as the json field is used in the unique_by.

If you change the json field to jsonb it works fine.

I saw that the noticed gem checks explicitly for jsonb support in their migration, maybe that's something you can incorporate as well:

https://github.com/excid3/noticed/blob/c0f63170bd8d4651684778650a1a07c07e04b58e/db/migrate/20231215190233_create_noticed_tables.rb#L7-L11

if t.respond_to?(:jsonb)
  t.jsonb :params
else
  t.json :params
end

Locally I ran the whole test suite on postgres with jsonb and there are two additional failures, but they seem to be related to how queries are formatted a bit differently with bind variables in Postgres.

.F

Failure:
AcidicJob::BasicsTest#test_workflow_with_db_IO_then_error_on_attempt_1_but_then_success_needs_idempotency_check_that_can_be_selective [test/acidic_job/basics_test.rb:493]:
Expected /SELECT\ 1\ AS\ one\ FROM\ "test_objects"\ LIMIT\ ?/ to match "SELECT 1 AS one FROM "test_objects" LIMIT $1".

bin/rails test /Users/dennis/Code/gems/acidic_job/test/acidic_job/basics_test.rb:429

..F

Failure:
AcidicJob::BasicsTest#test_workflow_with_database_IO_then_error_on_attempt_1_but_then_success_needs_idempotency_check [test/acidic_job/basics_test.rb:424]:
Expected /SELECT\ 1\ AS\ one\ FROM\ "test_objects"\ LIMIT\ ?/ to match "SELECT 1 AS one FROM "test_objects" LIMIT $1".

bin/rails test /Users/dennis/Code/gems/acidic_job/test/acidic_job/basics_test.rb:363

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