You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: handle re-save of postgres geometric types - #11857
The point and circle normalization logic checks for object type and property existence but doesn't validate that the properties are actually numbers. Invalid values like { x: null, y: undefined } or { x: 'string', y: 5 } could produce malformed SQL strings like (null,undefined) or (string,5).
This test file appears to be for testing BigInt with the In operator, which is unrelated to the geometric types issue described in the ticket. This may have been included by mistake or addresses a different issue entirely.
import"reflect-metadata"import"../../../utils/test-setup"import{DataSource,In}from"../../../../src"import{closeTestingConnections,createTestingConnections,reloadTestingDatabases,}from"../../../utils/test-utils"import{Author}from"./entity/Author"import{Book}from"./entity/Book"describe("find options > In operator with BigInt column",()=>{letconnections: DataSource[]before(async()=>(connections=awaitcreateTestingConnections({
__dirname,})),)beforeEach(()=>reloadTestingDatabases(connections))after(()=>closeTestingConnections(connections))it("should find books using In operator with bigint column",()=>Promise.all(connections.map(async(connection)=>{// Create test dataconstauthor1=connection.manager.create(Author,{name: "Author 1",})constauthor2=connection.manager.create(Author,{name: "Author 2",})constauthor3=connection.manager.create(Author,{name: "Author 3",})constsavedAuthor1=awaitconnection.manager.save(author1)constsavedAuthor2=awaitconnection.manager.save(author2)constsavedAuthor3=awaitconnection.manager.save(author3)constbook1=connection.manager.create(Book,{title: "Book 1",authorId: savedAuthor1.id,})constbook2=connection.manager.create(Book,{title: "Book 2",authorId: savedAuthor2.id,})constbook3=connection.manager.create(Book,{title: "Book 3",authorId: savedAuthor3.id,})awaitconnection.manager.save([book1,book2,book3])// Test using findBy with In operator (this should fail with the bug)constbooksRepository=connection.getRepository(Book)constauthorIds=[savedAuthor1.id,savedAuthor2.id]console.log("Testing with authorIds:",authorIds)console.log("Type of authorIds[0]:",typeofauthorIds[0])// This should work but fails with: "Validation failed for parameter '0'. Cannot convert [object Object] to a BigInt"constbooks=awaitbooksRepository.findBy({authorId: In(authorIds),})console.log("Found books:",books)books.should.have.lengthOf(2)books.map((b)=>b.title).should.include.members(["Book 1","Book 2"])}),))it("should find books using queryBuilder with bigint column (for comparison)",()=>Promise.all(connections.map(async(connection)=>{// Create test dataconstauthor1=connection.manager.create(Author,{name: "Author 1",})constauthor2=connection.manager.create(Author,{name: "Author 2",})constsavedAuthor1=awaitconnection.manager.save(author1)constsavedAuthor2=awaitconnection.manager.save(author2)constbook1=connection.manager.create(Book,{title: "Book 1",authorId: savedAuthor1.id,})constbook2=connection.manager.create(Book,{title: "Book 2",authorId: savedAuthor2.id,})awaitconnection.manager.save([book1,book2])// This should work (and it does according to the issue)constbooksRepository=connection.getRepository(Book)constauthorIds=[savedAuthor1.id,savedAuthor2.id]constbooks=awaitbooksRepository.createQueryBuilder("book").where("book.authorId IN (:...authorIds)",{
authorIds,}).getMany()books.should.have.lengthOf(2)}),))})
This test file is for MySQL closure table tree functionality and is completely unrelated to the Postgres geometric types issue. It should not be part of this PR.
import"reflect-metadata"import{DataSource}from"../../../../src/data-source/DataSource"import{closeTestingConnections,createTestingConnections,reloadTestingDatabases,}from"../../../utils/test-utils"import{expect}from"chai"import{Category}from"./entity/Category"// Confirms current behavior: countDescendants includes the node itself (returns 1 for leaf)describe("mysql > tree tables > closure-table countDescendants behavior",()=>{letconnections: DataSource[]before(async()=>(connections=awaitcreateTestingConnections({entities: [Category],enabledDrivers: ["mysql"],dropSchema: true,schemaCreate: true,})),)beforeEach(()=>reloadTestingDatabases(connections))after(()=>closeTestingConnections(connections))it("returns 1 for a leaf node (self-reference included)",()=>Promise.all(connections.map(async(connection)=>{constrepo=connection.getTreeRepository(Category)constroot=newCategory()root.name="root"awaitrepo.save(root)constcount=awaitrepo.countDescendants(root)expect(count).to.equal(1)}),))it("returns N for a node with N descendants",()=>Promise.all(connections.map(async(connection)=>{constrepo=connection.getTreeRepository(Category)constroot=newCategory()root.name="root"constchild=newCategory()child.name="child"child.parentCategory=rootawaitrepo.save(root)awaitrepo.save(child)constcount=awaitrepo.countDescendants(root)expect(count).to.equal(2)}),))})
Add validation for point and circle type objects to ensure they have all required properties (x, y for point; x, y, radius for circle), and throw an error if any are missing.
return DateUtils.mixedDateToDate(value)
} else if (columnMetadata.type === "point") {
- if (- typeof value === "object" &&- value.x !== undefined &&- value.y !== undefined- ) {+ if (typeof value === "object" && value !== null) {+ if (value.x === undefined || value.y === undefined) {+ throw new TypeORMError(+ `Value for point column is an object but is missing "x" or "y" property.`,+ )+ }
return `(${value.x},${value.y})`
}
return value
} else if (columnMetadata.type === "circle") {
- if (- typeof value === "object" &&- value.x !== undefined &&- value.y !== undefined &&- value.radius !== undefined- ) {+ if (typeof value === "object" && value !== null) {+ if (+ value.x === undefined ||2+ value.y === undefined ||2+ value.radius === undefined+ ) {+ throw new TypeORMError(+ `Value for circle column is an object but is missing "x", "y", or "radius" property.`,+ )+ }
return `<(${value.x},${value.y}),${value.radius}>`
}
return value
} else if (
["json", "jsonb", ...this.spatialTypes].indexOf(
columnMetadata.type,
[To ensure code accuracy, apply this suggestion manually]
Suggestion importance[1-10]: 7
__
Why: The suggestion correctly identifies that passing incomplete objects for point or circle types would lead to runtime errors, and proposes adding explicit validation to throw a descriptive error, which significantly improves the robustness of the new feature.
• The PR adds conversion logic in preparePersistentValue (lines 751-769) to convert point/circle
objects to PostgreSQL string format when writing to database
• However, it does NOT add corresponding logic in prepareHydratedValue to parse the string format
back to objects when reading from database
• The pg library returns geometric types as strings by default (e.g., '(10.5,20.3)' for point,
'<(4,5),12>' for circle)
• Without hydration logic, the tests will fail because they expect objects: line 52 expects `{ x:
10.5, y: 20.3 }, lines 90-94 expect { x: 4, y: 5, radius: 12 }`
+ } else if (columnMetadata.type === "point") {+ if (+ typeof value === "object" &&+ value.x !== undefined &&+ value.y !== undefined+ ) {+ return `(${value.x},${value.y})`+ }+ return value+ } else if (columnMetadata.type === "circle") {+ if (+ typeof value === "object" &&+ value.x !== undefined &&+ value.y !== undefined &&+ value.radius !== undefined+ ) {+ return `<(${value.x},${value.y}),${value.radius}>`+ }+ return value
Evidence
The PR implements only half of the round-trip conversion. The preparePersistentValue method handles
object-to-string conversion for writing, but prepareHydratedValue (which handles reading from
database) has no corresponding point/circle parsing logic. This pattern is inconsistent with other
types like vector, hstore, and cube which have both write and read conversions. The existing test
file column-types-postgres.test.ts (lines 173, 179) already expects point and circle to return as
objects, proving this hydration logic should exist.
## Issue Description
The PR adds object-to-string conversion for point and circle types in `preparePersistentValue` but is missing the corresponding string-to-object parsing in `prepareHydratedValue`. This breaks round-trip conversion and causes test failures.
## Issue Context
- PostgreSQL returns point as string format: `(x,y)` e.g., `(10.5,20.3)`
- PostgreSQL returns circle as string format: `<(x,y),radius>` e.g., `<(4,5),12>`
- Tests expect these to be parsed into objects: `{ x: number, y: number }` for point and `{ x: number, y: number, radius: number }` for circle
- Other geometric types like vector, hstore, and cube have similar parsing logic in prepareHydratedValue
## Fix Focus Areas
- src/driver/postgres/PostgresDriver.ts[838-968] - Add point and circle parsing logic in prepareHydratedValue method, similar to how vector (lines 863-874) and cube (lines 897-923) are handled
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
2. Stack traces logged in test error handlers 📘 Rule Violation
Description
• The test file logs full error stack traces using console.warn(err.stack) in error handlers
• This violates secure error handling practices as stack traces can expose internal implementation
details, file paths, and system architecture
• Stack traces should only be written to secure internal logs, not to console output which may be
visible in CI/CD pipelines or test reports
The compliance checklist requires that detailed error information including stack traces should only
be written to secure, internal logs (PR Compliance ID 4). The test code at lines 26 and 34 logs
stack traces to console.warn, which could expose internal system details in test output logs.
## Issue description
The test error handlers are logging full stack traces to console output, which can expose internal implementation details and violate secure error handling practices.
## Issue Context
This is a test file where error handlers catch exceptions during database setup/teardown. While debugging information is useful, stack traces should not be exposed in console output as they may be visible in CI/CD logs or test reports.
## Fix Focus Areas
- test/functional/spatial/postgres/geometric-spatial.test.ts[26-26]
- test/functional/spatial/postgres/geometric-spatial.test.ts[34-34]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
3. Missing input validation for geometric coordinates 📘 Rule Violation
Description
• The preparePersistentValue method for point and circle types lacks validation of numeric values
before string interpolation
• Values like value.x, value.y, and value.radius are directly interpolated into SQL strings
without checking if they are valid numbers
• This could lead to malformed SQL or unexpected behavior if non-numeric values are passed
+ } else if (columnMetadata.type === "point") {+ if (+ typeof value === "object" &&+ value.x !== undefined &&+ value.y !== undefined+ ) {+ return `(${value.x},${value.y})`+ }+ return value+ } else if (columnMetadata.type === "circle") {+ if (+ typeof value === "object" &&+ value.x !== undefined &&+ value.y !== undefined &&+ value.radius !== undefined+ ) {+ return `<(${value.x},${value.y}),${value.radius}>`+ }+ return value
Evidence
The compliance checklist requires robust error handling with edge case management including
validation of external inputs and proper handling of boundary values (PR Compliance ID 3). The new
code checks for property existence but does not validate that x, y, and radius are actually numeric
values before interpolating them into strings.
## Issue description
The point and circle type handlers directly interpolate coordinate values into SQL strings without validating that they are valid numbers. This could lead to malformed SQL if invalid values are provided.
## Issue Context
The preparePersistentValue method is responsible for converting JavaScript objects to PostgreSQL-compatible string formats. While it checks for property existence, it doesn't validate the numeric nature of the values.
## Fix Focus Areas
- src/driver/postgres/PostgresDriver.ts[751-759]
- src/driver/postgres/PostgresDriver.ts[760-769]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
4. No null safety check for object properties 📘 Rule Violation
Description
• The code checks value.x !== undefined but doesn't verify that value itself is not null before
accessing properties
• While typeof value === "object" is checked, in JavaScript typeof null === "object" returns
true, which could cause runtime errors
• This creates a potential edge case where null values could cause property access errors
+ if (+ typeof value === "object" &&+ value.x !== undefined &&+ value.y !== undefined+ ) {
Evidence
The compliance checklist requires explicit handling of edge cases including null values (PR
Compliance ID 3). The code uses typeof value === "object" which returns true for null in
JavaScript, potentially causing property access errors when checking value.x !== undefined.
## Issue description
The type check `typeof value === "object"` doesn't exclude null values, which could cause runtime errors when accessing properties like `value.x`.
## Issue Context
In JavaScript, `typeof null === "object"` returns true due to a historical quirk. The code should explicitly check that value is not null before attempting to access its properties.
## Fix Focus Areas
- src/driver/postgres/PostgresDriver.ts[752-756]
- src/driver/postgres/PostgresDriver.ts[761-766]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
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
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.
Description of change
PostgresDriver.tsPull-Request Checklist
Fixes #4004functional/geometric-spatial.test.ts)docs/docs/**.md)Fixes #4004