Обновление клиента с помощью REST API приводит к 500 внутренним ошибкам сервера - PullRequest
0 голосов
/ 22 апреля 2019

Я обновляю записи клиентов AR через API REST на основе контракта, используя PHP & Guzzle 6, и получаю ответ 500 Internal Server Error.

Сообщение об ошибке в ответе:

{
   "message": "An error has occurred.",
   "exceptionMessage": "Unable to cast object of type 'PX.Api.ContractBased.Models.EntityValueField' to type 'PX.Api.ContractBased.Models.EntitySearchField'.",
   "exceptionType": "System.InvalidCastException",
   "stackTrace": "... see below ..."
}

Трассировка стека:

at PX.Api.ContractBased.OData.FilterVisitor.SetNullableCondition(BinaryOperatorNode nodeIn, String nullCondition, String regularCondition)
at PX.Api.ContractBased.OData.FilterVisitor.VisitRoot(SingleValueNode root)
at PX.Api.ContractBased.OData.Helpers.FillRestQueryOptions(IEdmModel edmModel, EntityImpl entity, String filter, String select, String expand, String custom)
at lambda_method(Closure , Object , Object[] )
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()

Сначала я подумал, что это может быть связано с URL-адресом запроса, но после просмотра this ответ на аналогичный вопрос, по-видимому, не связан с параметрами, переданными в URL?

Я уже нашел «решение / обходной путь», удалив CustomerID из тела запроса, но, похоже,немного странно, что это необходимо для того, чтобы заставить запрос работать?

Я посмотрел документацию для обновления записи , но не вижу ничего, связанного с 'removeполе key при использовании параметра filter в URL-адресе запроса '.

Этот запрос возвращает внутреннюю ошибку сервера 500:

PUT entity/Default/18.200.001/Customer?$filter=CustomerID%20eq%20%27100000044%27&$select=CustomerID

{
   "CustomerClass": {
      "value": "CUSTOMER_CLASS"
   },
   "CustomerID": {
      "value": "100000044"
   },
   "CustomerName": {
      "value": "Christiaan Raubenheimer"
   },
   "MainContact": {
      "Address": {
         "AddressLine1": {
            "value": "Street Line 1"
         },
         "AddressLine2": {
            "value": "Stree Line 2"
         },
         "City": {
            "value": "City"
         },
         "Country": {
            "value": "ZA"
         },
         "PostalCode": {
            "value": "0000"
         },
         "State": {
            "value": "State"
         }
      },
      "Attention": {
         "value": "Christiaan Raubenheimer"
      },
      "DisplayName": {
         "value": "Company Name"
      },
      "Email": {
         "value": "...email address..."
      },
      "JobTitle": {
         "value": "Company Name"
      },
      "Phone1": {
         "value": "0000000000"
      }
   }
}

Этот запрос возвращает 200 успешных ответов:

PUT entity/Default/18.200.001/Customer?$filter=CustomerID%20eq%20%27100000044%27&$select=CustomerID

{
   "CustomerClass": {
      "value": "CUSTOMER_CLASS"
   },
   "CustomerName": {
      "value": "Christiaan Raubenheimer"
   },
   "MainContact": {
      "Address": {
         "AddressLine1": {
            "value": "Street Line 1"
         },
         "AddressLine2": {
            "value": "Stree Line 2"
         },
         "City": {
            "value": "City"
         },
         "Country": {
            "value": "ZA"
         },
         "PostalCode": {
            "value": "0000"
         },
         "State": {
            "value": "State"
         }
      },
      "Attention": {
         "value": "Christiaan Raubenheimer"
      },
      "DisplayName": {
         "value": "Company Name"
      },
      "Email": {
         "value": "...email address..."
      },
      "JobTitle": {
         "value": "Company Name"
      },
      "Phone1": {
         "value": "0000000000"
      }
   }
}

Итак, похоже, что требуется удалить CustomerID из тела запроса, как показано выше, но может ли быть, что я что-то упустил?

1 Ответ

2 голосов
/ 22 апреля 2019

Ошибка, вероятно, связана с тем, что вы смешиваете несколько способов выбора записи для ее обновления.

Вы используете 2 следующих способа:

  • Параметр Filter в URL
  • Поле ключа в теле записи

Пожалуйста, используйте только один из этих методов.

...