ApiLogicServer icon indicating copy to clipboard operation
ApiLogicServer copied to clipboard

SqlServer NORTHWND fails to add Category using Admin App

Open valhuber opened this issue 3 years ago • 5 comments

Here is the log:

ValidationError: Invalid type member: Categorie != Category

Traceback (most recent call last):
  File "/Users/val/dev/safrs/safrs/safrs_api.py", line 653, in method_wrapper
    result = fun(*args, **kwargs)
  File "/Users/val/dev/safrs/safrs/jsonapi.py", line 427, in post
    instance = self._create_instance(data)
  File "/Users/val/dev/safrs/safrs/jsonapi.py", line 452, in _create_instance
    raise ValidationError(f"Invalid type member: {obj_type} != {self.SAFRSObject._s_type}")
safrs.errors.ValidationError
Validation Error: Invalid type member: Categorie != Category
127.0.0.1 - - [02/Mar/2022 18:52:49] "POST /api/Categories HTTP/1.1" 400 -

It does work with Swagger; cURL:

curl -X POST "http://localhost:5656/api/Categories/" -H  "accept: application/vnd.api+json" -H  "Content-Type: application/json" -d "{  \"data\": {    \"attributes\": {      \"CategoryName\": \"test\"    },    \"type\": \"Category\"  }}"

Same error occurring on MySQL/Sakalia - Categories

ValidationError: Invalid type member: Categorie != Category

Traceback (most recent call last):
  File "/Users/val/dev/safrs/safrs/safrs_api.py", line 653, in method_wrapper
    result = fun(*args, **kwargs)
  File "/Users/val/dev/safrs/safrs/jsonapi.py", line 427, in post
    instance = self._create_instance(data)
  File "/Users/val/dev/safrs/safrs/jsonapi.py", line 452, in _create_instance
    raise ValidationError(f"Invalid type member: {obj_type} != {self.SAFRSObject._s_type}")
safrs.errors.ValidationError
Validation Error: Invalid type member: Categorie != Category
127.0.0.1 - - [02/Mar/2022 18:52:49] "POST /api/Categories HTTP/1.1" 400 -

valhuber avatar Mar 03 '22 02:03 valhuber

The "type" being sent must match the collection type. I don't know why your code posts "Categorie" instead of "Category".

The type defaults to the classname, it can be overriden if you'd wish to change it.

thomaxxl avatar Mar 06 '22 17:03 thomaxxl

This is using the Admin app

On Sun, Mar 6, 2022 at 9:33 AM Thomas Pollet @.***> wrote:

The "type" being sent must match the collection type. I don't know why your code posts "Categorie" instead of "Category".

The type defaults to the classname, it can be overriden if you'd wish to change it.

— Reply to this email directly, view it on GitHub https://github.com/valhuber/ApiLogicServer/issues/41#issuecomment-1060006170, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABKSG35YAW3E2XVXM4KU43TU6TT6FANCNFSM5PZGTN2A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

-- Thanks, Val

510-703-5909 valhuber on skype

valhuber avatar Mar 06 '22 18:03 valhuber

Here is the project no Categorie sqlserver.zip

valhuber avatar Mar 08 '22 15:03 valhuber

There is no "type" attribute in the admin.yaml. Compare with the resource "type" in https://apilogicserver.pythonanywhere.com/admin-app/index.html#/Configuration

thomaxxl avatar Mar 08 '22 17:03 thomaxxl

Hmm: here is the admin, I am seeing type, no?

resources:
  Categories:
    attributes:
      - label: ' Category Name*'
        name: CategoryName
        required: true
        search: true
        sort: true
      - name: Description
      - name: CategoryID
    tab_groups:
      - direction: tomany
        fks:
          - CategoryID
        name: ProductList
        resource: Products
    type: Category
    user_key: CategoryName

Maybe the problem is that table-name <> class-name. I am presuming it works like this.

This is the Jan 28 version, btw.

valhuber avatar Mar 08 '22 18:03 valhuber