From 4271af927c4ce0e1f10d617a5be53df56fd3a16e Mon Sep 17 00:00:00 2001 From: Gustaf Rosenblad Date: Sun, 17 Sep 2023 16:37:32 +0200 Subject: [PATCH 1/2] fix: Date should be backed by timestamp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … instead of timestamptz. Date is already UTC-based, no need to have PostgreSQL convert to UTC. This is breaking change. --- Sources/PostgresNIO/Data/PostgresData+Date.swift | 4 ++-- .../PostgresNIO/New/Data/Date+PostgresCodable.swift | 2 +- Tests/IntegrationTests/PerformanceTests.swift | 12 ++++++------ Tests/IntegrationTests/PostgresNIOTests.swift | 4 ++-- .../New/Data/Date+PSQLCodableTests.swift | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Sources/PostgresNIO/Data/PostgresData+Date.swift b/Sources/PostgresNIO/Data/PostgresData+Date.swift index 6d730f25..8a60806c 100644 --- a/Sources/PostgresNIO/Data/PostgresData+Date.swift +++ b/Sources/PostgresNIO/Data/PostgresData+Date.swift @@ -6,7 +6,7 @@ extension PostgresData { var buffer = ByteBufferAllocator().buffer(capacity: 0) let seconds = date.timeIntervalSince(_psqlDateStart) * Double(_microsecondsPerSecond) buffer.writeInteger(Int64(seconds)) - self.init(type: .timestamptz, value: buffer) + self.init(type: .timestamp, value: buffer) } public var date: Date? { @@ -39,7 +39,7 @@ extension PostgresData { @available(*, deprecated, message: "Deprecating conformance to `PostgresDataConvertible`, since it is deprecated.") extension Date: PostgresDataConvertible { public static var postgresDataType: PostgresDataType { - return .timestamptz + return .timestamp } public init?(postgresData: PostgresData) { diff --git a/Sources/PostgresNIO/New/Data/Date+PostgresCodable.swift b/Sources/PostgresNIO/New/Data/Date+PostgresCodable.swift index 31d8d749..ab632f58 100644 --- a/Sources/PostgresNIO/New/Data/Date+PostgresCodable.swift +++ b/Sources/PostgresNIO/New/Data/Date+PostgresCodable.swift @@ -3,7 +3,7 @@ import struct Foundation.Date extension Date: PostgresNonThrowingEncodable { public static var psqlType: PostgresDataType { - .timestamptz + .timestamp } public static var psqlFormat: PostgresFormat { diff --git a/Tests/IntegrationTests/PerformanceTests.swift b/Tests/IntegrationTests/PerformanceTests.swift index 6f730560..aa483e47 100644 --- a/Tests/IntegrationTests/PerformanceTests.swift +++ b/Tests/IntegrationTests/PerformanceTests.swift @@ -87,7 +87,7 @@ final class PerformanceTests: XCTestCase { """ "string" text, "int" int8, - "date" timestamptz, + "date" timestamp, "uuid" uuid, """, fixtureData: [ @@ -138,11 +138,11 @@ final class PerformanceTests: XCTestCase { "int3" int8, "int4" int8, "int5" int8, - "date1" timestamptz, - "date2" timestamptz, - "date3" timestamptz, - "date4" timestamptz, - "date5" timestamptz, + "date1" timestamp, + "date2" timestamp, + "date3" timestamp, + "date4" timestamp, + "date5" timestamp, "uuid1" uuid, "uuid2" uuid, "uuid3" uuid, diff --git a/Tests/IntegrationTests/PostgresNIOTests.swift b/Tests/IntegrationTests/PostgresNIOTests.swift index ea4d8d05..32c6835b 100644 --- a/Tests/IntegrationTests/PostgresNIOTests.swift +++ b/Tests/IntegrationTests/PostgresNIOTests.swift @@ -1058,7 +1058,7 @@ final class PostgresNIOTests: XCTestCase { "table2_id" int8, "intValue" int8, "stringValue" text, - "dateValue" timestamptz, + "dateValue" timestamp, PRIMARY KEY ("id") ); """).wait()) @@ -1070,7 +1070,7 @@ final class PostgresNIOTests: XCTestCase { "id" int8 NOT NULL, "intValue" int8, "stringValue" text, - "dateValue" timestamptz, + "dateValue" timestamp, PRIMARY KEY ("id") ); """).wait()) diff --git a/Tests/PostgresNIOTests/New/Data/Date+PSQLCodableTests.swift b/Tests/PostgresNIOTests/New/Data/Date+PSQLCodableTests.swift index 769bde4b..a2ec4402 100644 --- a/Tests/PostgresNIOTests/New/Data/Date+PSQLCodableTests.swift +++ b/Tests/PostgresNIOTests/New/Data/Date+PSQLCodableTests.swift @@ -9,7 +9,7 @@ class Date_PSQLCodableTests: XCTestCase { var buffer = ByteBuffer() value.encode(into: &buffer, context: .default) - XCTAssertEqual(Date.psqlType, .timestamptz) + XCTAssertEqual(Date.psqlType, .timestamp) XCTAssertEqual(buffer.readableBytes, 8) var result: Date? From da0ed4e140864fc53ccc9529ec911933508c2fbd Mon Sep 17 00:00:00 2001 From: Gustaf Rosenblad Date: Sun, 17 Sep 2023 17:33:38 +0200 Subject: [PATCH 2/2] feat: Removed generic description of errors --- Sources/PostgresNIO/New/PSQLError.swift | 22 ------------------- .../New/PostgresErrorTests.swift | 13 +---------- 2 files changed, 1 insertion(+), 34 deletions(-) diff --git a/Sources/PostgresNIO/New/PSQLError.swift b/Sources/PostgresNIO/New/PSQLError.swift index 7060a690..acada177 100644 --- a/Sources/PostgresNIO/New/PSQLError.swift +++ b/Sources/PostgresNIO/New/PSQLError.swift @@ -459,17 +459,6 @@ public struct PSQLError: Error { } } -extension PSQLError: CustomStringConvertible { - public var description: String { - // This may seem very odd... But we are afraid that users might accidentally send the - // unfiltered errors out to end-users. This may leak security relevant information. For this - // reason we overwrite the error description by default to this generic "Database error" - """ - PSQLError – Generic description to prevent accidental leakage of sensitive data. For debugging details, use `String(reflecting: error)`. - """ - } -} - extension PSQLError: CustomDebugStringConvertible { public var debugDescription: String { var result = #"PSQLError(code: \#(self.code)"# @@ -606,17 +595,6 @@ public struct PostgresDecodingError: Error, Equatable { } } -extension PostgresDecodingError: CustomStringConvertible { - public var description: String { - // This may seem very odd... But we are afraid that users might accidentally send the - // unfiltered errors out to end-users. This may leak security relevant information. For this - // reason we overwrite the error description by default to this generic "Database error" - """ - PostgresDecodingError – Generic description to prevent accidental leakage of sensitive data. For debugging details, use `String(reflecting: error)`. - """ - } -} - extension PostgresDecodingError: CustomDebugStringConvertible { public var debugDescription: String { var result = #"PostgresDecodingError(code: \#(self.code)"# diff --git a/Tests/PostgresNIOTests/New/PostgresErrorTests.swift b/Tests/PostgresNIOTests/New/PostgresErrorTests.swift index 33df5439..32cf4603 100644 --- a/Tests/PostgresNIOTests/New/PostgresErrorTests.swift +++ b/Tests/PostgresNIOTests/New/PostgresErrorTests.swift @@ -41,10 +41,7 @@ final class PSQLErrorTests: XCTestCase { var testBinds = PostgresBindings(capacity: 1) testBinds.append(1, context: .default) error1.query = .init(unsafeSQL: "TEST QUERY", binds: testBinds) - - XCTAssertEqual(String(describing: error1), """ - PSQLError – Generic description to prevent accidental leakage of sensitive data. For debugging details, use `String(reflecting: error)`. - """) + XCTAssertEqual(String(reflecting: error1), """ PSQLError(code: server, serverInfo: [sqlState: 00000, detail: More test message, file: PostgresNIOTests/PostgresErrorTests.swift, hint: It's a test, that's your hint, line: 0, message: Test message, position: 1, routine: testPSQLErrorDescription(), localizedSeverity: ERROR, severity: ERROR, columnName: testcol, dataTypeName: testtyp, constraintName: testcon, schemaName: testsch, tableName: testtab], query: PostgresQuery(sql: TEST QUERY, binds: [(****; BIGINT; format: binary)])) """) @@ -107,14 +104,6 @@ final class PostgresDecodingErrorTests: XCTestCase { line: 123 ) - // Plain description - XCTAssertEqual(String(describing: error1), """ - PostgresDecodingError – Generic description to prevent accidental leakage of sensitive data. For debugging details, use `String(reflecting: error)`. - """) - XCTAssertEqual(String(describing: error2), """ - PostgresDecodingError – Generic description to prevent accidental leakage of sensitive data. For debugging details, use `String(reflecting: error)`. - """) - // Extended debugDescription XCTAssertEqual(String(reflecting: error1), """ PostgresDecodingError(code: typeMismatch,\