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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timestampable models test fails in linux #1710

Closed
gperdomor opened this issue Jun 5, 2018 · 6 comments
Closed

Timestampable models test fails in linux #1710

gperdomor opened this issue Jun 5, 2018 · 6 comments

Comments

@gperdomor
Copy link
Contributor

Test fails with Timestampable model in linux

Steps to reproduce

Download this source code, run docker-compose build and then docker-compose test
todo-demo.zip

Expected behavior

The same behavior on Mac, tests green 馃槃

Actual behavior

Tests not pass:
<EXPR>:0: error: TodoTests.testGettingASingleTodoFromTheAPI : threw error "鈿狅笍 [DecodingError.typeMismatch: Value of type 'Double' required for key 'createdAt'.]"

Environment

  • Vapor Framework version: 3.0.3
  • Vapor Toolbox version: 3.1.7
  • OS version: Linux (Swift 4.1 Docker image)
@gperdomor
Copy link
Contributor Author

removing (or commenting) this portion of code (you can leave the createdAt and updatedAt as model properties), tests pass again

extension Todo: Timestampable {
    static var createdAtKey: WritableKeyPath<Todo, Date?> {
        return \.createdAt
    }

    static var updatedAtKey: WritableKeyPath<Todo, Date?> {
        return \.updatedAt
    }
}

@proggeramlug
Copy link
Contributor

What this boiled down for me is that Swift/Fluent/Vapor (not sure exactly which one) has a bug when using \.created. Technically it should return a WritableKeyPath that correctly identifies the table and column. For some odd reason that is not happening correctly sometimes.

What it will do is, once you check the SQL logs, to instead of choosing the correct column it picks "the first one available". So it will try to assign id to Date? (or so) and that will obviously cause for it to fail.

I'm not in a position where I can debug this in detail yet but I may later today. As said I've experienced the same bug before and my solution often looks like this:

QueryField(entity: Model.entity, name: "correctNameHere")

Which is defeating the purpose of having the convenient way of writing that, however it does work.

@tanner0101
Copy link
Member

My guess is this is a bug in the PostgreSQLRowDecoder(), probably something to do with difference in dictionary hashing between Darwin and Linux. I bet it's already solved in the latest development branches. Looking into it now.

@proggeramlug
Copy link
Contributor

@tanner0101 I've had the same bug in MySQL as well though - have there been updates addressing this some time recently?

@tanner0101
Copy link
Member

Hmm actually think it might be a much simpler problem. I'm seeing the response come back as:

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
content-length: 97
{"title":"My Todo!","createdAt":"2018-06-05T07:48:59Z","updatedAt":"2018-06-05T07:48:59Z","id":1}

And @gperdomor is trying to decode this model using default JSONDecoder.

/// A single entry of a Todo list.
final class Todo: PostgreSQLModel {
    static let entity = "todos"
    
    /// The unique identifier for this `Todo`.
    var id: Int?

    /// A title describing what this `Todo` entails.
    var title: String

    var createdAt: Date?
    var updatedAt: Date?
    var deletedAt: Date?

    /// Creates a new `Todo`.
    init(id: Int? = nil, title: String) {
        self.id = id
        self.title = title
    }
}

The dates are formatted ISO8601 which I don't think Linux supports in Swift 4.1.

@MrLotU
Copy link
Sponsor Member

MrLotU commented Nov 17, 2019

With Vapor 4 in Beta and no discussion for over a few months, I'm closing this issue. Feel free to re-open if there are still questions/issues unanswered.

@MrLotU MrLotU closed this as completed Nov 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants