ApiLogicServer icon indicating copy to clipboard operation
ApiLogicServer copied to clipboard

Master/Detail add not saving details (feature request)

Open valhuber opened this issue 4 years ago • 4 comments

On the default database, this POST from the Tutorial does not save OrderDetails:

curl -X POST "http://localhost:5000/Order/"
-H "accept: application/vnd.api+json" -H "Content-Type: application/json"
-d "
{ "data": {
"attributes": {
"CustomerId": "ALFKI",
"EmployeeId": 1,
"Freight": 10},
"relationships": {
"OrderDetailList":
[ {
"ProductId": 1,
"Quantity": 1
} ]
},
"type": "Order"
}
}"

valhuber avatar Feb 17 '21 22:02 valhuber

I (sort of) added this functionality (https://github.com/thomaxxl/safrs/commit/b8405f5f725da5021b647babc88303fdf6846b89) .

But, following POST

curl -X POST "http://localhost:5000/Order/" \
-H "accept: application/vnd.api+json" -H "Content-Type: application/json" \
-d '
{
  "data": {
    "attributes": {
      "CustomerId": "ALFKI",
      "EmployeeId": 1,
      "Freight": 10
    },
    "relationships": {
      "OrderDetailList": {
        "data": [
          {
            "type": "OrderDetail",
            "id": "1"
          }
        ]
      }
    },
    "type": "Order"
  }
}
'

throws an error:

  File "/home/automat/tmp/ApiLogicServer/venv/lib/python3.8/site-packages/logic_bank/exec_row_logic/logic_row.py", line 837, in insert
    self.copy_rules()
  File "/home/automat/tmp/ApiLogicServer/venv/lib/python3.8/site-packages/logic_bank/exec_row_logic/logic_row.py", line 263, in copy_rules
    each_copy_rule.execute(logic_row, parent_logic_row)
  File "/home/automat/tmp/ApiLogicServer/venv/lib/python3.8/site-packages/logic_bank/rule_type/copy.py", line 45, in execute
    each_column_value = getattr(parent_logic_row.row, self._from_column)
AttributeError: 'NoneType' object has no attribute 'UnitPrice'
[2021-02-25 15:45:11,577] ERROR: 'NoneType' object has no attribute 'UnitPrice'
[2021-02-25 15:45:11,577] ERROR in app: Exception on /Order/ [POST]

In my tests it's possible to do something like this:

curl -X POST "http://localhost:5000/api/Books/" -H  "accept: application/vnd.api+json" -H  "Content-Type: application/json" -d '{
  "data": {
    "attributes": {
        "title": "test"
    },
    "relationships": {
      "reader": {
        "data": {
          "id": null,
          "type": "Person",
          "attributes": {
            "name": "boo"
          }
        }
      }
    },
    "type": "Book",
    "id": "0b22014c-bcb7-4d89-9851-9d99bca16590"
  }
}'

There are a couple of things I don't like about this implementation, so it'll probably change.

thomaxxl avatar Feb 25 '21 14:02 thomaxxl

Not sure we are still pursuing this path, but I did try it out with git-current safrs, got this error

{ "errors": [ { "title": "Validation Error: Invalid relationship payload: {'type': 'OrderDetail', 'ProductId': 1, 'Quantity': 1, 'Discount': 0}", "detail": "Validation Error: Invalid relationship payload: {'type': 'OrderDetail', 'ProductId': 1, 'Quantity': 1, 'Discount': 0}", "code": 400 } ] } Respo

Posting this

{ "data": { "attributes": { "CustomerId": "ALFKI", "EmployeeId": 1, "Freight": 10 }, "relationships": { "OrderDetailList": { "data": [ { "type": "OrderDetail", "ProductId": 1, "Quantity": 1, "Discount": 0 }, { "type": "OrderDetail", "ProductId": 2, "Quantity": 2, "Discount": 0 } ] } }, "type": "Order" } }

On Feb 25, 2021, at 6:51 AM, Thomas Pollet [email protected] wrote:

I (sort of) added this functionality (thomaxxl/safrs@b8405f5 https://github.com/thomaxxl/safrs/commit/b8405f5f725da5021b647babc88303fdf6846b89) .

But, following POST

curl -X POST "http://localhost:5000/Order/"
-H "accept: application/vnd.api+json" -H "Content-Type: application/json"
-d ' { "data": { "attributes": { "CustomerId": "ALFKI", "EmployeeId": 1, "Freight": 10 }, "relationships": { "OrderDetailList": { "data": [ { "type": "OrderDetail", "id": "1" } ] } }, "type": "Order" } } ' throws an error:

File "/home/automat/tmp/ApiLogicServer/venv/lib/python3.8/site-packages/logic_bank/exec_row_logic/logic_row.py", line 837, in insert self.copy_rules() File "/home/automat/tmp/ApiLogicServer/venv/lib/python3.8/site-packages/logic_bank/exec_row_logic/logic_row.py", line 263, in copy_rules each_copy_rule.execute(logic_row, parent_logic_row) File "/home/automat/tmp/ApiLogicServer/venv/lib/python3.8/site-packages/logic_bank/rule_type/copy.py", line 45, in execute each_column_value = getattr(parent_logic_row.row, self._from_column) AttributeError: 'NoneType' object has no attribute 'UnitPrice' [2021-02-25 15:45:11,577] ERROR: 'NoneType' object has no attribute 'UnitPrice' [2021-02-25 15:45:11,577] ERROR in app: Exception on /Order/ [POST] In my tests it's possible to do something like this:

curl -X POST "http://localhost:5000/api/Books/" -H "accept: application/vnd.api+json" -H "Content-Type: application/json" -d '{ "data": { "attributes": { "title": "test" }, "relationships": { "reader": { "data": { "id": null, "type": "Person", "attributes": { "name": "boo" } } } }, "type": "Book", "id": "0b22014c-bcb7-4d89-9851-9d99bca16590" } }' There are a couple of things I don't like about this implementation, so it'll probably change.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/valhuber/ApiLogicServer/issues/11#issuecomment-785951152, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABKSG32ZV27JLW2IFK7XXXDTAZPXPANCNFSM4XZGCEQQ.

valhuber avatar Mar 03 '21 00:03 valhuber

Hi,

I've switched off adding relationships, but it can be enabled by setting SAFRSBase._s_allow_add_rels = True

To get Services/add_order, I use this: https://gist.github.com/thomaxxl/5952973073800c71835826aa18bccc3f

[image: image.png]

On Wed, 3 Mar 2021 at 01:50, Val Huber [email protected] wrote:

Not sure we are still pursuing this path, but I did try it out with git-current safrs, got this error

{ "errors": [ { "title": "Validation Error: Invalid relationship payload: {'type': 'OrderDetail', 'ProductId': 1, 'Quantity': 1, 'Discount': 0}", "detail": "Validation Error: Invalid relationship payload: {'type': 'OrderDetail', 'ProductId': 1, 'Quantity': 1, 'Discount': 0}", "code": 400 } ] } Respo

Posting this

{ "data": { "attributes": { "CustomerId": "ALFKI", "EmployeeId": 1, "Freight": 10 }, "relationships": { "OrderDetailList": { "data": [ { "type": "OrderDetail", "ProductId": 1, "Quantity": 1, "Discount": 0 }, { "type": "OrderDetail", "ProductId": 2, "Quantity": 2, "Discount": 0 } ] } }, "type": "Order" } }

On Feb 25, 2021, at 6:51 AM, Thomas Pollet [email protected] wrote:

I (sort of) added this functionality (thomaxxl/safrs@b8405f5 < https://github.com/thomaxxl/safrs/commit/b8405f5f725da5021b647babc88303fdf6846b89>) .

But, following POST

curl -X POST "http://localhost:5000/Order/"
-H "accept: application/vnd.api+json" -H "Content-Type: application/json"
-d ' { "data": { "attributes": { "CustomerId": "ALFKI", "EmployeeId": 1, "Freight": 10 }, "relationships": { "OrderDetailList": { "data": [ { "type": "OrderDetail", "id": "1" } ] } }, "type": "Order" } } ' throws an error:

File "/home/automat/tmp/ApiLogicServer/venv/lib/python3.8/site-packages/logic_bank/exec_row_logic/logic_row.py", line 837, in insert self.copy_rules() File "/home/automat/tmp/ApiLogicServer/venv/lib/python3.8/site-packages/logic_bank/exec_row_logic/logic_row.py", line 263, in copy_rules each_copy_rule.execute(logic_row, parent_logic_row) File "/home/automat/tmp/ApiLogicServer/venv/lib/python3.8/site-packages/logic_bank/rule_type/copy.py", line 45, in execute each_column_value = getattr(parent_logic_row.row, self._from_column) AttributeError: 'NoneType' object has no attribute 'UnitPrice' [2021-02-25 15:45:11,577] ERROR: 'NoneType' object has no attribute 'UnitPrice' [2021-02-25 15:45:11,577] ERROR in app: Exception on /Order/ [POST] In my tests it's possible to do something like this:

curl -X POST "http://localhost:5000/api/Books/" -H "accept: application/vnd.api+json" -H "Content-Type: application/json" -d '{ "data": { "attributes": { "title": "test" }, "relationships": { "reader": { "data": { "id": null, "type": "Person", "attributes": { "name": "boo" } } } }, "type": "Book", "id": "0b22014c-bcb7-4d89-9851-9d99bca16590" } }' There are a couple of things I don't like about this implementation, so it'll probably change.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub < https://github.com/valhuber/ApiLogicServer/issues/11#issuecomment-785951152>, or unsubscribe < https://github.com/notifications/unsubscribe-auth/ABKSG32ZV27JLW2IFK7XXXDTAZPXPANCNFSM4XZGCEQQ .

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/valhuber/ApiLogicServer/issues/11#issuecomment-789337368, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA77EHTHTOXNBT3PM37676TTBWBTPANCNFSM4XZGCEQQ .

thomaxxl avatar Mar 03 '21 07:03 thomaxxl

Right... as I said, probably going with the RPC approach.

Any luck with the “no entity” example? As you saw in Skype, I was not able to get the override to work. Perhaps fastest to do a screen share later today, since probably something I did wrong...?

Best, Val

On Tue, Mar 2, 2021 at 11:21 PM Thomas Pollet [email protected] wrote:

Hi,

I've switched off adding relationships, but it can be enabled by setting SAFRSBase._s_allow_add_rels = True

To get Services/add_order, I use this: https://gist.github.com/thomaxxl/5952973073800c71835826aa18bccc3f

[image: image.png]

On Wed, 3 Mar 2021 at 01:50, Val Huber [email protected] wrote:

Not sure we are still pursuing this path, but I did try it out with git-current safrs, got this error

{ "errors": [ { "title": "Validation Error: Invalid relationship payload: {'type': 'OrderDetail', 'ProductId': 1, 'Quantity': 1, 'Discount': 0}", "detail": "Validation Error: Invalid relationship payload: {'type': 'OrderDetail', 'ProductId': 1, 'Quantity': 1, 'Discount': 0}", "code": 400 } ] } Respo

Posting this

{ "data": { "attributes": { "CustomerId": "ALFKI", "EmployeeId": 1, "Freight": 10 }, "relationships": { "OrderDetailList": { "data": [ { "type": "OrderDetail", "ProductId": 1, "Quantity": 1, "Discount": 0 }, { "type": "OrderDetail", "ProductId": 2, "Quantity": 2, "Discount": 0 } ] } }, "type": "Order" } }

On Feb 25, 2021, at 6:51 AM, Thomas Pollet [email protected] wrote:

I (sort of) added this functionality (thomaxxl/safrs@b8405f5 <

https://github.com/thomaxxl/safrs/commit/b8405f5f725da5021b647babc88303fdf6846b89

) .

But, following POST

curl -X POST "http://localhost:5000/Order/"
-H "accept: application/vnd.api+json" -H "Content-Type: application/json"
-d ' { "data": { "attributes": { "CustomerId": "ALFKI", "EmployeeId": 1, "Freight": 10 }, "relationships": { "OrderDetailList": { "data": [ { "type": "OrderDetail", "id": "1" } ] } }, "type": "Order" } } ' throws an error:

File

"/home/automat/tmp/ApiLogicServer/venv/lib/python3.8/site-packages/logic_bank/exec_row_logic/logic_row.py",

line 837, in insert

self.copy_rules() File

"/home/automat/tmp/ApiLogicServer/venv/lib/python3.8/site-packages/logic_bank/exec_row_logic/logic_row.py",

line 263, in copy_rules

each_copy_rule.execute(logic_row, parent_logic_row) File

"/home/automat/tmp/ApiLogicServer/venv/lib/python3.8/site-packages/logic_bank/rule_type/copy.py",

line 45, in execute

each_column_value = getattr(parent_logic_row.row, self._from_column) AttributeError: 'NoneType' object has no attribute 'UnitPrice' [2021-02-25 15:45:11,577] ERROR: 'NoneType' object has no attribute 'UnitPrice' [2021-02-25 15:45:11,577] ERROR in app: Exception on /Order/ [POST] In my tests it's possible to do something like this:

curl -X POST "http://localhost:5000/api/Books/" -H "accept: application/vnd.api+json" -H "Content-Type: application/json" -d '{ "data": { "attributes": { "title": "test" }, "relationships": { "reader": { "data": { "id": null, "type": "Person", "attributes": { "name": "boo" } } } }, "type": "Book", "id": "0b22014c-bcb7-4d89-9851-9d99bca16590" } }' There are a couple of things I don't like about this implementation, so it'll probably change.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <

https://github.com/valhuber/ApiLogicServer/issues/11#issuecomment-785951152

, or unsubscribe <

https://github.com/notifications/unsubscribe-auth/ABKSG32ZV27JLW2IFK7XXXDTAZPXPANCNFSM4XZGCEQQ

.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub < https://github.com/valhuber/ApiLogicServer/issues/11#issuecomment-789337368 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AA77EHTHTOXNBT3PM37676TTBWBTPANCNFSM4XZGCEQQ

.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/valhuber/ApiLogicServer/issues/11#issuecomment-789499105, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABKSG36RSDGHPQUXI2HJ4UDTBXPOFANCNFSM4XZGCEQQ .

-- Thanks, Val

510-703-5909 valhuber on skype

valhuber avatar Mar 03 '21 11:03 valhuber