Number is not a subtype of Null

A frustrating error.

Number is not a subtype of Null

What does that mean?

Do you have field definitions in your collection schema?

Was there any more to the error message? The image cuts off the bottom of the shell, so just making sure.

I agree this is odd. Another way to phrase the error should be “Expected type Null, encountered Number”. I don’t know why that would be the case. That’s why I am asking about the schema.

Yes, thanks, this is the schema

collection Message {
  readLimit: Int
  content: String
  key: String
  
  ttl_days 3
  unique [.key]
  
  index by_key {
    terms [.key]
  }
}

Incidentally, I got around this by I think casting to any type:

let doc: Any = Message.by_key("_yju2kq0rn").first()
let n: Int = doc!.readLimit
if (doc!.readLimit == 1) {
    // need to delete because now it is at 0
    doc!.delete()
    doc { content, key, readLimit }
} else {
    doc!.update({
        readLimit: n! - 1
    }) { content, key, readLimit }
}

Thanks for the additional info! This definitely looks like an issue on our end. I’ve created an internal issue for our engineers to prioritize a fix.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.