appwrite / sdk-for-cli

[READ-ONLY] Official Appwrite CLI >_
BSD 3-Clause "New" or "Revised" License
85 stars 28 forks source link

🐛 Bug Report: Cannot deploy collections in appwrite.json with Int Attributes #124

Closed maximilianmaihoefner closed 5 minutes ago

maximilianmaihoefner commented 2 years ago

👟 Reproduction steps

  1. Create a new Integer Attribute via the Web Interface, enter a name and leave all other fields empty and click create.
  2. Connect the Appwrite CLI 2.0 using appwrite login
  3. Create appwrite.json using appwrite init --all
  4. Inspect the Integer Attribute in appwrite.json, it should show a min/max value of -9223372036854776000/9223372036854776000.
  5. Try to deploy the appwrite.json using appwrite deploy collection
  6. Choose the collection and confirm the overwrite.
  7. An Error gets thrown.

👍 Expected behavior

Should be able to apply the created appwrite.json.

It would also be nice if the error message could specify the allowed min/max values, or a bit more description why the passed value is invalid.

👎 Actual Behavior

$ appwrite deploy collection ? Which collections would you like to deploy? MyCollection (62212c12df87ffcd4478) ℹ Info Deploying collection MyCollection ( 62212c12df87ffcd4478 ) ℹ Info Collection MyCollection ( 62212c12df87ffcd4478 ) already exists. ? Are you sure you want to override this collection? This can lead to loss of data! Type "YES" to confirm. YES ℹ Info Updating attributes ... ✗ Error Invalid min: Value must be a valid integer

🎲 Appwrite version

Different version (specify in environment)

💻 Operating system

MacOS

🧱 Your Environment

Using Appwrite 0.13.0 but that isn't available in the 'Appwrite version'-Dropdown yet.

The Server was upgraded from 0.12.1 using the instructions at: https://appwrite.io/docs/upgrade running the Install and Data Migration commands.

👀 Have you spent some time to check if this issue has been raised before?

🏢 Have you read the Code of Conduct?

maximilianmaihoefner commented 2 years ago

This is the full appwrite.json-File created by the CLI:

{
    "projectId": "test",
    "projectName": "Test",
    "collections": [
        {
            "$id": "62212c12df87ffcd4478",
            "$read": [],
            "$write": [],
            "name": "MyCollection",
            "enabled": true,
            "permission": "collection",
            "attributes": [
                {
                    "key": "myIntAttribute",
                    "type": "integer",
                    "status": "available",
                    "required": false,
                    "array": false,
                    "min": -9223372036854776000,
                    "max": 9223372036854776000,
                    "default": null
                }
            ],
            "indexes": []
        }
    ]
}
christyjacob4 commented 2 years ago

@maximilianmaihoefner Thank you for reporting this. We'll look into it 🙂

stnguyen90 commented 2 years ago

FYI, min value is -9223372036854775808 and max value is 9223372036854775807.

Something seems to be rounding the values to -9223372036854776000 and 9223372036854776000….

Meldiron commented 2 years ago

I can confirm this problem is on the server side, not in the SDK. Same values are provided in Appwrite Console and the error above cones from axios (HTTP client) error.

Meldiron commented 2 years ago

Looks like the issue is a mismatch between the maximum allowed integer between size and Javascript (all numbers in js are like float, making safe max int lower). Ill work on a PR where we add support for big integers when parsing/stringifying jsons.

Meldiron commented 2 years ago

The problem was addressed in 0.14 release 😇 Feel free to re-open issue if after upgrading you still encounter the problem.

noob8boi commented 1 year ago

The problem was addressed in 0.14 release 😇 Feel free to re-open issue if after upgrading you still encounter the problem.

I am currently 0.15.1 and I am facing the same issue. No idea why (using 0.18.4 CLI)

LDY681 commented 1 year ago

FYI, min value is -9223372036854775808 and max value is 9223372036854775807.

Something seems to be rounding the values to -9223372036854776000 and 9223372036854776000….

I found the same issue with appwrite console. I am currently on the v1.3.4. After I created an attribute w/o specifying min and max and edited again. These two fields were filled with -9223372036854776000 and 9223372036854776000. Thus causing an error and prevent me to edit other attributes.

sonicviz commented 6 months ago

I'm trying to run through this Stripe tutorial and running into the same issue with the "created at" integer field. https://dev.to/appwrite/start-selling-online-using-appwrite-and-stripe-3l04

            {
                "key": "createdAt",
                "type": "integer",
                "status": "available",
                "required": true,
                "array": false,
                "min": -9223372036854776000,
                "max": 9223372036854776000,
                "default": null
            }

✗ Error Invalid max param: Value must be a valid integer

appwrite deploy collection ? Which collections would you like to deploy? Orders (xxxx - orders) ℹ Info Deploying collection Orders ( xxx- orders ) ✓ Success Updated undefined (xxx ) ℹ Info Collection Orders ( orders ) already exists. ? Are you sure you want to override this collection? This can lead to loss of data! Type "YES" to confirm. YES ℹ Info Deleting indexes and attributes ... ✗ Error Invalid min param: Value must be a valid integer

Any solution?

sonicviz commented 6 months ago

Update: As pointed out above (and by Kenny in discord) "FYI, min value is -9223372036854775808 and max value is 9223372036854775807."

            {
                "key": "createdAt",
                "type": "integer",
                "status": "available",
                "required": true,
                "array": false,
                "min": -9223372036854775808,
                "max": 9223372036854775807,
                "default": null
            }
tripolskypetr commented 3 months ago

Still not fixed in appwrite 1.5

tripolskypetr commented 3 months ago

Thank god I knew the auto generated cli will never work well and made ci/cd scripts

https://github.com/react-declarative/appwrite-backup-tool

stnguyen90 commented 3 months ago

As mentioned in this related discord thread, I think the problem is due to how BigNumber is stringified here:

https://github.com/appwrite/sdk-for-cli/blob/8511dcdff5435abbcd0c39507f458857c60c93c2/lib/client.js#L170

I think we should try using JSONbig.stringify() like we do here:

https://github.com/appwrite/sdk-for-cli/blob/8511dcdff5435abbcd0c39507f458857c60c93c2/lib/config.js#L27