Azure / Azure/data-api-builder

[Bug]: JSON data in POST request is handled as text

Open
#2,817 0 comments 1 reaction 0 assignees View on GitHub
bug cri pgsql triage
Dominant language
C#
Stars
1.5k
Forks
370
Avg merge
3d 17h
Merged PRs (30d)
8

Description

### What happened?

When doing a POST request that includes data that should be put in a JSON column (in PostgreSQL), it is handled as text and the insert fails.

Image

I expected the value to be inserted into the database.

### Version

1.5.56+61c726a0fc38ab5a1d9e52cc3593bbd2a8633aec

### What database are you using?

PostgreSQL

### What hosting model are you using?

Custom Docker host

### Which API approach are you accessing DAB through?

REST

### Relevant log output

```Text
fail: Azure.DataApiBuilder.Service.Controllers.RestController[0]

f3eefcf8-c1ce-47c2-9e21-d9d748e421d7 Error handling REST request.

Azure.DataApiBuilder.Service.Exceptions.DataApiBuilderException: 42804: column "u_response" is of type json but expression is of type text

POSITION: 62

---> Npgsql.PostgresException (0x80004005): 42804: column "u_response" is of type json but expression is of type text

POSITION: 62

at Npgsql.Internal.NpgsqlConnector.ReadMessageLong(Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)

at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)

at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)

at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)

at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)

at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)

at Npgsql.NpgsqlCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)

at Azure.DataApiBuilder.Core.Resolvers.QueryExecutor`1.ExecuteQueryAgainstDbAsync[TResult](TConnection conn, String sqltext, IDictionary`2 parameters, Func`3 dataReaderHandler, HttpContext httpContext, String dataSourceName, List`1 args) in /_/src/Core/Resolvers/QueryExecutor.cs:line 296

Exception data:

Severity: ERROR

SqlState: 42804

MessageText: column "u_response" is of type json but expression is of type text

Hint: You will need to rewrite or cast the expression.

Position: 62

File: parse_target.c

Line: 585

Routine: transformAssignedExpr

--- End of inner exception stack trace ---
```

### Code of Conduct

- [x] I agree to follow this project's Code of Conduct

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.