Repository navigation
Fix keyword enum constants, interrupts at BEGIN/COMMIT, Ruby 3.1 RuboCop and pg re-prepare after DEALLOCATE ALL - #54
Merged
Conversation
…by 3.1 unnamed columns and re-preparing after DEALLOCATE ALL - Enum values that are not valid constant names (BEGIN/END keywords, the module's own ALL) get a trailing _; duplicates after normalisation get _2, _3, ... - transaction runs BEGIN / COMMIT / ROLLBACK with interrupts deferred (Thread.handle_interrupt) and rolls back when BEGIN or COMMIT itself raises, on pg, mysql2 and sqlite3. - Struct rows (Ruby < 3.2) built with column_1: keywords disable Naming/VariableNumber around the method. - pg prepares a statement again when DEALLOCATE ALL / DISCARD ALL dropped it (outside a transaction). - README: MySQL JSON is a String; document enum constant names, interrupts and re-preparing. Co-Authored-By: Doron Eli Rachman <doron050@gmail.com>
Contributor
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Co-Authored-By: Doron Eli Rachman <doron050@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the three bugs found in the pre-release sweep, and checks the two suspicions. Each fix comes with a test that fails on
main.Bugs
'begin'/'end'generatedBEGIN = 'begin', which is a SyntaxError, so the whole package failed to load.'all'collided with the module'sALLlist.Code.constant_nameadds_toBEGIN/END/ALL(END_,ALL_).unique_constantsadds_2,_3, ... until the name is free, including names it produced itself.test_enum_values_named_like_ruby_keywords_get_valid_constants(E2E pg + mysql2). Newstepenums round-trip every value:begin,end,all,BEGIN,nil,self,__FILE__,do.BEGIN/COMMIT(pg, mysql2, sqlite3). Before, aTimeout/Thread#raisethat arrived right afterBEGINreturned skipped the rollback, so the connection went back to the pool inside an open transaction. The same happened whenCOMMITitself raised before it ran.Fix:
transactionruns insideThread.handle_interrupt(Object => :never), and only the block runs with:immediate.BEGINruns inside the protectedbegin, and the rescue rolls back whenBEGINran. IfCOMMITraises, the transaction is rolled back.legacy_transaction_template(Ruby < 3.3) is adapted to the new layout.Test:
test_interrupts_around_begin_and_commit_never_leave_the_{connection,database}_in_a_transaction(E2E, all three engines). A client or database lands one of these deterministically:Thread#raiseright afterBEGIN,BEGIN,COMMIT.The test then checks that nothing is left open and that later calls commit.
Naming/VariableNumberon Ruby < 3.2 (all engines). Before,Structrows of unnamed columns were built withGetUnnamedColumnsRow.new(column_1: ...).MethodGendisablesNaming/VariableNumberaround a method whose keyword row/model constructor names end in_<digits>.test_ruby31_struct_rows_of_unnamed_columns_are_rubocop_clean(unit, because RuboCop on generated code is not reachable from E2E). It generates every fixture withrubyVersion: 3.1and runs the Naming cops.Suspicions
DEALLOCATE ALL/DISCARD ALL: this is a real bug. Every later call on that pooled connection raisedPG::InvalidSqlStatementName. Prepared execution now goes through arun_preparedhelper, which prepares a dropped statement again when the connection is outside a transaction. Inside a transaction the error has already aborted it, so the error is raised and the transaction rolls back. Test:test_statements_are_prepared_again_after_deallocate_all(E2E pg).JSONcolumns and parameters are JSON textStrings, which is whatmysql2returns and what the RBS already declares.Other changes
examples/regenerated, golden files rewritten,test/fixtures/{pg,mysql2}.binre-captured with sqlc 1.27.0, andsteep_expectations.ymlrefreshed.Thread.handle_interruptwithout a block (fixed in RBS master), so Steep reportsUnexpectedBlockGiven.docs/Coverage.mdare updated.Checklist
examples/is regenerated (rake sqlc_generate_process) and committedrake test, andrake end2end_*when the generated code changes)rake rubocop) and Steep-clean (rake steep)bug,enhancement,documentation, orbreaking) so the release notes are grouped correctly