Empty User-Agent causes sql exception column "os" violates not-null constraint - wso2

Having WSO2AM (API Manager) 2.1.0 with an Analytics server (on PostgreSQL) we see following issue:
if a client call an API with no User-Agent header, the analytics server is unable to complete processing and in the logs of the analytics server (wso2carbon.log) there are following exceptions:
TID: [-1] [] [2017-10-10 10:55:17,292] ERROR {org.apache.spark.executor.Executor} - Exception in task 0.0 in stage 41522.0 (TID 32785) {org.apache.spark.executor.Executor}
java.sql.BatchUpdateException: Batch entry 0 INSERT INTO API_REQ_USER_BROW_SUMMARY (api, version, apiPublisher, tenantDomain, total_request_count, year, month, day, requestTime, os, browser) VALUES ('agenda.brussels', '0.0.2', 'admin', 'carbon.super', 1, 2017, 10, 10, 1507625491000, NULL, NULL) ON CONFLICT (api,version,apiPublisher,year,month,day,os,browser,tenantDomain) DO UPDATE SET total_request_count=EXCLUDED.total_request_count, requestTime=EXCLUDED.requestTime was aborted: ERROR: null value in column "os" violates not-null constraint
Detail: Failing row contains (agenda.brussels, 0.0.2, admin, carbon.super, 1, 2017, 10, 10, 1507625491000, null, null). Call getNextException to see other errors in the batch.
at org.postgresql.jdbc.BatchResultHandler.handleError(BatchResultHandler.java:145)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2156)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:460)
at org.postgresql.jdbc.PgStatement.executeBatch(PgStatement.java:793)
at org.postgresql.jdbc.PgPreparedStatement.executeBatch(PgPreparedStatement.java:1659)
...
Caused by: org.postgresql.util.PSQLException: ERROR: null value in column "os" violates not-null constraint
Detail: Failing row contains (agenda.brussels, 0.0.2, admin, carbon.super, 1, 2017, 10, 10, 1507625491000, null, null).
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2455)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2155)
... 16 more
Apparently the "os" field is assumed as not empty. The APIs and clients are public, so we have no way to enforce the request sent from the clients.
I'd see temporary measures
set some User-Agent value if empty in the http proxy level (I am not sure if we are allowed to)
is it feasible to update the processing script to use coalesce postgresql function? (returning some default value of null argument is used).
Questions:
is it a bug (known/unknown) or we missed something? If so, what would be the best way to resolve it?
Thank all for any hint

Related

How to deal with django migration postgres deadlock?

So, I was deploying the django app to production and then the infamous postgres deadlock situation happened. This happens during the django migration.
Django version: 3.2
Postgres 13
Google cloud sql postgres.
OperationalError
deadlock detected
DETAIL: Process 112506 waits for AccessExclusiveLock on relation 29425 of database 27145; blocked by process 112926.
Process 112926 waits for RowShareLock on relation 29381 of database 27145; blocked by process 112506.
HINT: See server log for query details.
I ran this query to get the process info:
SELECT 29425::regclass,29381::regclass from pg_locks;
and result:
regclass | regclass
"custom_requestlog" "auth_user"
"custom_requestlog" "auth_user"
I am not sure how to proceed ahead, as the pgaudit has been enabled but it doesnt show anything and also the query insights is not that helpful. Attached is image of query insights.
Any help would be helpful please!
Update:
The query from log explorer in Google cloud, gave this query just after deadlock detected error:
2022-04-29 13:51:36.590 UTC [6445]: [732-1] db=xyz_prod,user=backend-prod DETAIL: Process 6445 waits for AccessExclusiveLock on relation 29425 of database 27145; blocked by process 9249.
Process 9249 waits for RowShareLock on relation 29381 of database 27145; blocked by process 6445.
Process 6445: SET CONSTRAINTS "custom_requestlog_user_id_3ff3f1cf_fk_some_user_id" IMMEDIATE; ALTER TABLE "custom_requestlog" DROP CONSTRAINT "custom_requestlog_user_id_3ff3f1cf_fk_some_user_id"
Process 9249: INSERT INTO "custom_requestlog" ("user_id", "ip_addr", "url", "session_key", "method", "headers", "query", "body", "cookies", "timestamp", "status_code", "response_snippet") VALUES (NULL, 'xx.xxx.xx.xxx'::inet, '/version/', NULL, 'GET', '{"HTTP_HOST": "api.some.com", "HTTP_ACCEPT": "*/*", "HTTP_ACCEPT_ENCODING": "deflate, gzip", "HTTP_USER_AGENT": "GoogleStackdriverMonitoring-UptimeChecks(https://cloud.google.com/monitoring)", "HTTP_X_CLOUD_TRACE_CONTEXT": "xxxxxx/9771676669485105781", "HTTP_VIA": "1.1 google", "HTTP_X_FORWARDED_FOR": "xx.xxx.xx.xxx, xx.xxx.xx.xxx", "HTTP_X_FORWARDED_PROTO": "https", "HTTP_CONNECTION": "Keep-Alive"}', '{}', '\x'::bytea, '{}', '2022-04-29T13:48:46.844830+00:00'::timestamptz, 200, NULL) RETURNING "custom_requestlog"."id"

Updating Sales Order line items in Dynamics business central

I have a sales order created using API for business central. Sales order has a single line item. I want to update the quantity of line item. Following is what I have tried so far.
Endpoint: https://api.businesscentral.dynamics.com/v1.0/domain.com/api/v1.0/companies(company_id)/salesOrders(sales_order_ide)/salesOrderLines(sales_order_line_id)
where sales order line id is of the form e86d3aa1-f2f8-ea11-aa61-0022481e3b8c-10000
as described in this document When a PATCH request is made, I get the following exception:
')' or ',' expected at position 9 in
'(sale-order-line-item-id)'.
The exception stated above was also occuring when i was simply trying to get the line item but that was fixed when I changed the URL and it took the form:
Endpoint:
https://api.businesscentral.dynamics.com/v1.0/domain.com/api/v1.0/companies(b4a4beb2-2d42-40dc-9229-5b5c371be4e3)/salesOrders(e86d3aa1-f2f8-ea11-aa61-0022481e3b8c)/salesOrderLines?filter=sequence eq 10000
This endpoint is returning correct response when i try to get the line item by issuing
GET request. However, when I issue a PATCH request using the same endpoint, with a simple request body e.g.
{"quantity" : 2.0}
it throws the exception:
'PATCH' requests for 'salesOrderLines' of EdmType 'Collection' are not
allowed within Dynamics 365 Business Central OData web services.
I am also specifying the if-Match header along with the request that contains etag value for the line item but of no avail and same exception is occurring. Am I missing something? Any help will be appreciated.
For those who may visit this question later, after much hit and trial through Postman, I finally figured out the problem. In my case if-Match header that's basically is Etag for the line item is all fine. The Problem was with API URL, specifically the way we specify the line item id. We have to specify this in single quotes so the URL for API call becomes:
https://api.businesscentral.dynamics.com/v1.0/domain.com/api/v1.0/companies(company_id)/salesOrders(sales_order_ide)/salesOrderLines('sales_order_line_id')
You would note that we are not specifying company_id and sales_order_id in single quotes, reason being, both of these parameters a of type GUID whereas sales_order_line_id is of type string as per metadata document.
I am getting below error
{
"error": {
"code": "BadRequest_NotFound",
"message": "Bad Request - Error in query syntax."
}
}

After success validation also getting error message but its processing in oracle apex

Dynamic Action ->When:click button->If:True->submit page.here i am doing a validation with a sql query.
SELECT * FROM TAB_MASTER
WHERE REQUEST_ID=:P4_SELECTED_REQ_ID AND (upper(USER_NAME)=upper(:APP_USER) OR
EXISTS (SELECT NULL FROM USER_ACCOUNT WHERE USER_ROLE='ADMIN' AND upper(USER_NAME)=upper(:APP_USER)));
means request can be confirmed by same user or another user with ADMIN role.if the above query will return 1 row only should process otherwise error message (no process).If there is no record(another user and no admin role) its working fine.but when it return 1 record(another user and admin role) its processing but error message is getting pop up what used for FALSE condition.
Also tried to set value to the output sql query to a hidden field then used validation as plsql/expression :HIDDEN_FIELD=1,but no luck.

Apollo client useQuery fails to return cached data when variables are changed

Consider the following queries
useQuery(POSTS, {
variables: {
offset: currPage * 20
}
})
where currPage is a React local state variable. It will get updated when user paginates
Intended outcome:
When currPage=1, new data is fetched, when currPage=2, new data is fetched... When user paginates to the previous page (page 1), because query with currPage=1 is already fetched, it should just read the cache
Actual outcome:
When user paginates from page 1 to page 2, new data for page 2 is fetched, however, when user paginates back to page 1, cache is not read, data is still displayed for page 2
Versions
Apollo client version: #apollo/client: ^3.0.0-beta.14
This bug is also reported in Apollo client GitHub: https://github.com/apollographql/apollo-client/issues/5659

error using django-admin with django-mssql

I am using django 1.6 with django-mssql
My django admin site works perfectly except for one part.
Whenever I click an "add user" link or otherwise navigate to /admin/auth/user/add I get the following error
(-2147352567, 'Exception occurred.', (0, u'Microsoft OLE DB Provider for SQL Server', u'Cannot issue SAVE TRANSACTION when there is no active transaction.', None, 0, -2147467259), None)
Command:
SAVE TRANSACTION [s3612_x1]
Parameters:
[]
I've tried various seetings in my database config such as "use_mars": true but there has been no change.
I am able to create users in code by using the User model without issue.
I have not encountered this error anywhere else.
Fixed by setting 'ATOMIC_REQUESTS': True for my db connection, which I should have been doing anyway.