sdk-for-cli icon indicating copy to clipboard operation
sdk-for-cli copied to clipboard

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

Open maximilianmaihoefner opened this issue 3 years ago • 13 comments

👟 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?

  • [X] I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

maximilianmaihoefner avatar Mar 03 '22 21:03 maximilianmaihoefner

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": []
        }
    ]
}

maximilianmaihoefner avatar Mar 03 '22 21:03 maximilianmaihoefner

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

christyjacob4 avatar Mar 04 '22 08:03 christyjacob4

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

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

stnguyen90 avatar Mar 05 '22 04:03 stnguyen90

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 avatar Mar 07 '22 14:03 Meldiron

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 avatar Apr 11 '22 14:04 Meldiron

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

Meldiron avatar Jun 09 '22 10:06 Meldiron

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)

noob8boi avatar Sep 06 '22 12:09 noob8boi

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.

LDY681 avatar Jun 19 '23 08:06 LDY681

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 avatar Jan 01 '24 14:01 sonicviz

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
            }

sonicviz avatar Jan 03 '24 00:01 sonicviz

Still not fixed in appwrite 1.5

tripolskypetr avatar Mar 29 '24 18:03 tripolskypetr

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

tripolskypetr avatar Mar 29 '24 18:03 tripolskypetr

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

stnguyen90 avatar Apr 08 '24 22:04 stnguyen90