Code Monkey home page Code Monkey logo

Comments (10)

FatumaA avatar FatumaA commented on September 24, 2024 2

Ok, I have reproduced this bug. It's a bit nuanced. There is no error from Appwrite because it turns your string into an int but returns a string in the create event response. If you then fetch the documents it will return the new entry with the correct type.

My thoughts are that Appwrite should either:

  • Throw an error when you pass anything that is not an int
  • Or it should return the create response with the attribute as an int after it parses it to int type in the background

from appwrite.

issasaleh avatar issasaleh commented on September 24, 2024 2

Ok, I have reproduced this bug. It's a bit nuanced. There is no error from Appwrite because it turns your string into an int but returns a string in the create event response. If you then fetch the documents it will return the new entry with the correct type.

My thoughts are that Appwrite should either:

  • Throw an error when you pass anything that is not an int
  • Or it should return the create response with the attribute as an int after it parses it to int type in the background

Yes,

Because the "Create event" returns the data before parsing it, it will cause issues if I expect an int from request.body in the function and get a string instead.

I think the most effective solution is the first one you suggested:

  • Throw an error when you pass anything that is not an int

from appwrite.

abnegate avatar abnegate commented on September 24, 2024 1

@stnguyen90 This is intentional, it would just add unnecessary friction to throw an error if the string is a valid integer. The event should definitely fire with with an int though.

from appwrite.

FatumaA avatar FatumaA commented on September 24, 2024

It seems you have passed the amount a string value so it inferred it as a string, did you explicitly set the amount as int in appwrite? or set the type of amount to be an int type somewhere else in the code?

from appwrite.

issasaleh avatar issasaleh commented on September 24, 2024

It seems you have passed the amount a string value so it inferred it as a string, did you explicitly set the amount as int in appwrite? or set the type of amount to be an int type somewhere else in the code?

The AMOUNT attribute is an int in appwrite, it should never accept Numbers as strings, ever.

But from what I see it accepts numbers as Strings then maybe it got parsed in the process in appwrite before it reaches the database but__ the function event caught it before it got parsed, and this is the issue with that, if a programming error happens in the front end and the programmer pass the value as a string, appwrite should throw an error,

If I'm expecting to get an int value from the function event but got String instead that will cause problems.

Why parse the value and then write it to the database when you can make it only acceptΒ intΒ simply?

from appwrite.

issasaleh avatar issasaleh commented on September 24, 2024

It seems you have passed the amount a string value so it inferred it as a string, did you explicitly set the amount as int in appwrite? or set the type of amount to be an int type somewhere else in the code?

try the Reproduction steps...

from appwrite.

stnguyen90 avatar stnguyen90 commented on September 24, 2024

Throw an error when you pass anything that is not an int

Yes, I agree we should throw an error if the incorrect type is passed.

Would either of you be interested in working on this?

from appwrite.

FatumaA avatar FatumaA commented on September 24, 2024

I'd love to give it a shot

from appwrite.

IOAPP-IO avatar IOAPP-IO commented on September 24, 2024

@stnguyen90 This is intentional, it would just add unnecessary friction to throw an error if the string is a valid integer. The event should definitely fire with with an int though.

The it should return the create response with the attribute as an int after it parses it to int type in the background..

from appwrite.

stnguyen90 avatar stnguyen90 commented on September 24, 2024

This is intentional, it would just add unnecessary friction to throw an error if the string is a valid integer. The event should definitely fire with with an int though.

@abnegate, so where and how would be the best place to convert the attribute such that we don't miss anything and we handle all attribute? The Structure validation should only be for validation and shouldn't mutate the data, right? Would we need to update encode()?

from appwrite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.