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

Sequel::Model definition raises a transaction unsupported error #12

Open
ZimbiX opened this issue Mar 21, 2022 · 0 comments
Open

Sequel::Model definition raises a transaction unsupported error #12

ZimbiX opened this issue Mar 21, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@ZimbiX
Copy link
Owner

ZimbiX commented Mar 21, 2022

Raised in an email from Leonardo Falcao (@lfalcao?) - thanks!

I had no idea that there was an issue with Sequel::Model, as I don't use it; personally preferring to use dry-struct and the repository pattern. I would have expected it to work, having partially implemented schema fetching in #schema_parse_table.

Defining a Sequel model calls #transaction internally, which seemed to be bypassing the transaction buffering; so Sequel::Model(db[:book]) is understandably failing with:

Sequel::DatabaseError: Google::Cloud::InvalidArgumentError: Transaction control statements are supported only in scripts or sessions
from /home/brendan/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/google-cloud-bigquery-1.38.1/lib/google/cloud/bigquery/dataset.rb:2777:in `rescue in ensure_job_succeeded!'

I have a WIP that makes definition work by using a session (related: #11), which I'll push shortly.

@ZimbiX ZimbiX added the bug Something isn't working label Mar 21, 2022
ZimbiX added a commit that referenced this issue Mar 21, 2022
Contributes to #11 and #12.

Currently this uses the one session for every query, but the docs say that prevents concurrency. They also say a session gets deleted after 24 hours, which I think would mean that limiting the use of the single session to transactions would cause still problems for an app with greater uptime than that. I think I need to make it create a new session at the start of each top-level transaction, and stop using the session at the end of it.

Sequel::Model:

The implementation of `#schema_parse_table` was incomplete, and so was preventing a Sequel model from being defined (it inspects the table schema). However, it seems that the method isn't actually essential (or at least, isn't anymore?). I don't recall what necessitated implementing it, but removing it does let a Sequel model be defined successfully. For better support, this should probably be added back later with a full implementation.

Note that saving a Sequel model also does work now, but isn't error-free yet:

```
Sequel::Error: can't express [] as a SQL literal
from /home/brendan/Projects/sequel/lib/sequel/dataset/sql.rb:1319:in `literal_other_append'
```

`#transaction` works now, but manually running `begin` probably doesn't, since it lacks the `; select 1` workaround: googleapis/google-cloud-ruby#9617 (comment).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant