Skip to content

URL is not supported as a postgres codable type #255

@rosslebeau

Description

@rosslebeau

Describe the bug

URL doesn't automatically work as a field type with underlying database type 'string'. It can't encode the URL properly.

To Reproduce

Have a model with this field:

@Field(key: "link")
var link: URL

And a migration like this:

func prepare(on database: Database) async throws {
      try await database.schema("bookmarks")
          .id()
          .field("link", .string, .required)
          .create()
  }

Then when you try to create one of these and save it to the database, you get this error:

invalid field: 'link', type: URL, error: Swift.DecodingError.dataCorrupted(Swift.DecodingError.Context(codingPath: [SomeCodingKey(stringValue: "bookmarks_link (2)", intValue: nil)], debugDescription: "Unable to interpret value of PSQL type TEXT: ByteBuffer { readerIndex: 0, writerIndex: 23, readableBytes: 23, capacity: 23, storageCapacity: 2048, slice: _ByteBufferSlice { 197..<220 }, storage: 0x000000011f00c200 (2048 bytes) }", underlyingError: nil)) [request-id: E5B62897-697A-468F-94A7-F6B5726CC7FB]

Expected behavior

The model and field are saved properly to the database.

Environment

  • Vapor Framework version: 4.86.2
  • Vapor Toolbox version: 18.7.4
  • OS version: macOS 14.1 (23B74)
  • Fluent version: 4.8.0
  • fluent-postgres-driver version: 2.8.0

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions