Repository navigation
fix: ORM log safety, @name in strings, TLS warning - #24
Conversation
useSSL: true maps to sslMode require. It encrypts the data but does not check the server certificate. The default stays the same. The driver now prints one warning to stderr, and the docs say to use verify-full.
The debug log prints every bound value as plain text, like password hashes and tokens. ConnectionConfig.logRedact takes a list of names. A value whose key ends with one of them is shown as ***. The default is an empty list, so the log output does not change.
The text of whereRaw and orWhereRaw goes into the SQL as it is. The doc comments now say to never put user input in it and to use @name params, the same as orderByRaw.
MySQL and SQLite changed every @name to a ? parameter, even inside a quoted string or a comment. Then the query had the wrong number of values and failed. Now the replacement skips quoted strings, quoted names and comments, like the Postgres driver does.
The log printed values in the order they were added to the map. So where(...).update(...) showed the WHERE value before the SET values. Now the log lists them in the order of the ? in the query. Only the log changes, the query is the same.
FileQueryPrinter opened, wrote and closed the log file on every query, and the query waited for the disk. Now it keeps the lines in memory and appends them in one async write, in order. flush() waits until every line is in the file, so no line is lost before exit().
When an owner has many child rows, hasOne eager loading keeps the last row the query returns. The database does not promise an order. The docs now say to add an orderBy in onQuery to pick the row. The behaviour does not change.
Logger.warn printed blue (34m), but its doc comment says yellow. It now uses the yellow colour code (33m).
Bot reviewVerdict: CHANGES NEEDED
What I checked and found OK
Do the tests fail without the fix?
Results
|
The background write changed what 3.0.1 apps get: lines were lost on exit(), a file read right after a query was empty, and write errors were no longer thrown. The sync write is the default again. The background write is now opt-in with buffered: true, plus flush().
MySQL runs the SQL inside /*! ... */ and /*M! ... */, so they are not comments. 3.0.1 replaced @name inside them. The new parser skipped them, so such a query failed. In MySQL mode they are now read as normal SQL. The doc also says that NO_BACKSLASH_ESCAPES is not handled.
Apps that use sslmode require on purpose had no way to hide the warning. extra['sslWarning'] = false (or sslWarning=false in the url) now turns it off. The doc says it prints once per isolate, because isolates share no memory.
Fixer replyFixed all points. Three new commits on the same branch.
Still no breaking changes. Results
|
Bot reviewVerdict: OK
Results
|
Eight small fixes in
dox_orm. One commit per item.No breaking changes. The old behaviour stays the default. New options are opt-in. All new API is added, nothing is removed or renamed.
1. Warning when Postgres TLS does not check the certificate
useSSL: trueuses TLS moderequire. It encrypts the data, but it does not check the server certificate. The default does not change. Now the app prints one warning to stderr (once per isolate) when it connects withrequire. The warning says to setextra['sslMode'] = 'verify-full'. Setextra['sslWarning'] = false(orsslWarning=falsein the url) to turn it off. It prints once per isolate: isolates share no memory, so once per process needs a shared file or similar, which is too much for a warning. The doc comments ofuseSSLandpostgresSslModesay the same.2. Opt-in redaction in the debug query log
The debug log prints every bound value as plain text, like password hashes and tokens. New:
ConnectionConfig.logRedact(alsoSqlQueryBuilder().logRedact). It is a list of names, like['password', 'token']. A value whose key ends with one of the names is shown as***. The default is an empty list, so the log does not change unless you set it. It also works with aDATABASE_URLconfig.3. Doc warning on
whereRawandorWhereRawThe doc comments now say: never put user input in the raw text, pass values as
@nameparams. Same asorderByRaw.4.
@nameinside strings and comments on MySQL and SQLiteMySQL and SQLite changed every
@nameto?, even inside a quoted string or a comment. Then the query had the wrong number of values and failed. Now the replacement skips'...',"...",`...`,--,/* */and (MySQL)#comments, like the Postgres driver. On MySQL a\escapes a quote in a string, and--is a comment only when a space follows. Unknown@word(like@@sql_mode) is still kept as it is. MySQL/*! ... */and/*M! ... */blocks are run by MySQL, so@nameinside them is still replaced, as in 3.0.1. A server withNO_BACKSLASH_ESCAPESis not handled (doc note).5. Query log value order
The log listed values in the order they were added to the map. So
where(...).update(...)showed the WHERE value first. Now the values follow the order of the?in the query. Values that the query does not use come last. Only the log changes.6. Opt-in buffered
FileQueryPrinterIt opens, writes and closes the file on every query. This stays the default: each line is in the file before
log()returns, and write errors are thrown, as in 3.0.1. New opt-in:FileQueryPrinter(file: f, buffered: true)keeps the lines in memory and appends them in the background, in order.flush()waits until every line is in the file (eg. beforeexit()). In buffered mode a write error prints to stderr.7. Doc note on
hasOnewith many rowsWhen an owner has many child rows, eager loading keeps the last row. Which row is picked does not change. The docs now say to add an
orderByinonQueryto pick the row.8.
Logger.warncolourIt printed blue (
34m). Its doc says yellow. It now prints yellow (33m).Not done
toSnakeCase(Address2toaddress_2) is skipped. Changing it would rename columns, so it is breaking.Tests
test/tls_warning_test.dart,test/named_params_test.dart,test/query_log_test.dart, and one test intest/where_clauses_test.dartthat runs awhereRawwith@namein a string and in comments on the real database.dart formatanddart analyze --fatal-infos packages: clean.