Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL is not supported as a postgres codable type #255

Closed
rosslebeau opened this issue Nov 15, 2023 · 0 comments · Fixed by #257
Closed

URL is not supported as a postgres codable type #255

rosslebeau opened this issue Nov 15, 2023 · 0 comments · Fixed by #257
Assignees
Labels
bug Something isn't working

Comments

@rosslebeau
Copy link

rosslebeau commented Nov 15, 2023

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
@rosslebeau rosslebeau added the bug Something isn't working label Nov 15, 2023
@gwynne gwynne self-assigned this Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants