-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid format is too short #220
Comments
I have the same problem with LocalDateTime column (timestamp in Postgres) |
Same problem with LocalDateTime |
Out of curiosity, what version of Slick, slick-pg and Postgres JDBC are you guys using? I'm only asking because I had pretty much the same problem a while back when I upgraded my version of the JDBC driver from I haven't looked at this since, but I tried to reproduce it just now with Slick |
Scratch that - it does seem to be broken still. Everything works fine with Postgres driver version
I had a quick look at the issues for the Postgres driver on GitHub (https://github.com/pgjdbc/pgjdbc) and didn't immediately see anything related, so maybe this is somehow expected behavior? I don't have much experience with using JDBC directly, so I can't tell... @tminglei - what do you think? |
Hey guys, I just upgraded posgres driver to I haven't reproduced the problem, maybe you guys can paste some reproducable codes? I tried |
Hi, I will try to write a failing test during the weekend, see if I can isolate it. Thanks On 17 October 2015 11:44:48 CEST, "涂名雷" notifications@github.com wrote:
|
Hi. I could not isolate this in a standalone project but I managed to write a test on my project where this happens. I have the following code:
If I remove a single one of those db.run(...result) then the test will be green. I don't do any special setup, just create some tables and this test runs alone, no other tests are running before/after/during. This is really weird. Thank you |
@motns I have this error with both 9.4-1201-jdbc41 and 9.4-1202-*and above |
Can you guys provide reproduce codes? I can't reproduce it yet. |
Hi, I have the same error since the 0.10.1 release. The code is very simple, I try to fetch an user with a 'createdAt' field (TIMESTAMPTZ) in a Postgresql database. The first fetch is good, the "user.createdAt" equals to "2015-10-20 14:43:45.602+02" but the next, contains only the datetime without timezone "2015-10-20 14:43:45.602". I have this code:
And the error:
Thanks a lot |
For me, this occurs at random it seems (Postgres 9.4.5, 9.4-1204-jdbc41, slick-pg 0.10.1). I don't know if this is related to slick-pg, as it gets fed a date time that is too short (it's missing the date time offset part like mentioned previously). The weird thing is that when I just start my Play app, it works a couple of times, after that it stops working and I get each time the error described above. I'll see if I can get an app out there that demonstrates this problem. |
I tried the following:
When I get the error, the |
I see the same problem. slick-pg 0.10.0, postgresql driver 9.4-1203-jdbc42. |
In codes of I debugged into postgres driver, and here's the related codes of // in AbstractJdbc2ResultSet.java
public String getString(int columnIndex) throws SQLException
{
checkResultSet( columnIndex );
if (wasNullFlag)
return null;
// varchar in binary is same as text, other binary fields are converted to their text format
if (isBinary(columnIndex) && getSQLType(columnIndex) != Types.VARCHAR) {
Object obj = internalGetObject(columnIndex, fields[columnIndex - 1]);
if (obj == null) {
return null;
}
// hack to be compatible with text protocol
if (obj instanceof java.util.Date) {
return connection.getTimestampUtils().timeToString((java.util.Date) obj);
}
if ("hstore".equals(getPGType(columnIndex))) {
return HStoreConverter.toString((Map) obj);
}
return trimString(columnIndex, obj.toString());
}
Encoding encoding = connection.getEncoding();
try
{
return trimString(columnIndex, encoding.decode(this_row[columnIndex - 1]));
}
catch (IOException ioe)
{
throw new PSQLException(GT.tr("Invalid character data was found. This is most likely caused by stored data containing characters that are invalid for the character set the database was created in. The most common example of this is storing 8bit data in a SQL_ASCII database."), PSQLState.DATA_ERROR, ioe);
}
} Note: for So if the column's format is |
But the column format is always |
So you are able to reproduce it now? In my case the field is |
I have a REST endpoint that produces exactly the same SQL request on each call. Problem happens only when I repeat this call several times on busy server (apache benchmark is a good tool for it). Single requests in non-busy development environment usually works fine. |
@DamirV, I haven't reproduced it yet. I just found a possible cause. |
I've got a bit more information: In my project(slick 3.0.3, slick-pg 0.9.0, postgresql 9.4-1201-jdbc41) I used https://github.com/tototoshi/slick-joda-mapper for joda DateTime. After switching to slick-pg's implicits tests started to throw this error. |
@prettynatty, I can't still reproduce it, with your tips. |
I still can't localize it to a small project. |
Hello, I can confirm, that this bug also occurs with ZonedDateTime and correct data sets in the Postgresql database. We use: In the Postgresql table the following timestamp with time zone is stored: We get the following error: 2015-11-18 14:01:10,815 [error] a.a.OneForOneStrategy - Text '2015-11-10 15:51:08.497' could not be parsed at index 23
java.time.format.DateTimeParseException: Text '2015-11-10 15:51:08.497' could not be parsed at index 23
at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1947) ~[na:1.8.0_45-internal]
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1849) ~[na:1.8.0_45-internal]
at java.time.ZonedDateTime.parse(ZonedDateTime.java:597) ~[na:1.8.0_45-internal]
at com.github.tminglei.slickpg.PgDate2Support$Date2DateTimeFormatters$$anonfun$4.apply(PgDate2Support.scala:78) ~[slick-pg_date2_2.11-0.10.1.jar:0.10.1]
at com.github.tminglei.slickpg.PgDate2Support$Date2DateTimeFormatters$$anonfun$4.apply(PgDate2Support.scala:78) ~[slick-pg_date2_2.11-0.10.1.jar:0.10.1] The time zone is not delivered to Would it be a solution to set the system time zone, if no time zone is available? We tested also with the following postgresql versions: |
@faustas, can you always reproduce it? If yes, can you debug into BTW, I can't reproduce it on my local. |
Hello, I debugged the application and can tell you the following. Within The following code As far as I understand the problem:
The final problem is the type conversion into ZonedDateTime which expects a Timezone at the parsed string. The Postgresql guys seem to have some problems in returning Timestamp with / without timezone correctly.
It would be great, if slick-pg could provide a workaround and select the values correctly. |
Thanks @faustas, you confirmed my guess! But I haven't a good solution to resolve it yet. |
@tminglei Would it be possible to change the fetching logic for timestamp related values? I'm thinking in the direction of pulling them out as formatted datetime strings and parsing them afterwards. So far writing these values seems to work, therefore it should suffice to change the "read logic". I currently have no idea how to implement that and I know that this is a "hack" but it would maybe provide a useable workaround as long as the postgresql guys haven't fixed that. |
@jan0sch, this is what I did in But the returned value See the So, as pgjdbc/pgjdbc#373 and pgjdbc/pgjdbc#304 pointed out, the root cause is postgres sent back binary (float or long) w/o time zone instead time string to jdbc driver. |
Ah, okay. So the problem is that the column is a binary one. Which means we would have to wait for a fix from the postgresql side or store timstamp values as strings and that would be rather ugly. :-( |
This is just a quickshot but would something like this maybe provide a workaround until this is officially fixed?
|
The motivation for this came through an issue with slick-pg (tminglei/slick-pg#220) which originates from the behaviour of the pgjdbc driver. This is an rather ugly hack but it may prevent the problems described in the issue above until this is officially fixed.
@tminglei Would it be possible to downgrade the JDBC version back to a version that worked? I think for some people (I know definitely for me), thats what caused the issue. Then maybe we should wait for the people at postgres-jdbc to fix the problem on their end |
@mdedetrich, I won't mind to do it, if it can really resolve the problem. So I'm not sure whether we should do it. |
For me it did solve the problem (9.4-1201-jdbc41 and using OffsetDateTime). |
Well, I think I found the cause. There's a method in public void setPrepareThreshold(int newThreshold) throws SQLException {
checkClosed();
if (newThreshold < 0) {
forceBinaryTransfers = true;
newThreshold = 1;
}
this.m_prepareThreshold = newThreshold;
} And from postgres driver The So, downgrade to I will do it ASAP. |
Hi all, I downgrade postgres driver to 9.4-1201-jdbc41, and released slick-pg Pls update your project dependencies to use it. |
Thanks for the update! Getting something in production on tuesday and was hopping to not making the experiment with the workaround :) |
Have this same problem. Downgrading the driver fixes it. |
FWIW, I didn't see this issue and had the same problem. I worked around it by replacing the column type to one mapped to time stamp instead of mapped to String. I will test with the lower Postrgresql version today. |
@tminglei Not sure why, but I am still getting this in the latest version of slick-pg v0.14.2, and I have cycled through the following postgres jdbc versions "org.postgresql" % "postgresql" % "9.4-1201-jdbc41" force(),
"org.postgresql" % "postgresql" % "9.4-1206-jdbc41" force(),
"org.postgresql" % "postgresql" % "9.4.1208.jre7" force() And I am getting an error in all of the cases. Any suggestions? |
dont import any driver, there should be one bundled in the pg-slick dependency |
@Daxten Its not working on my end, also the one that is bundled with pg-slick is also one of the ones that I tried before "org.postgresql" % "postgresql" % "9.4-1201-jdbc41" force() You can check here https://github.com/tminglei/slick-pg/blob/v0.14.2/project/Build.scala#L71 I am suspecting that its an issue with using |
It seems like this problem has been fixed in jdbc driver 9.4.2109 version (tested on psql 9.5.3, slick 3.1.1 and slick-pg-0.14.2). |
@timothyklim What version of postgresql jdbc is 9.4.2109, such a version doesn't seem to exist? https://mvnrepository.com/artifact/org.postgresql/postgresql Or are you talking about the raw main JDBC driver? |
bet he ment 1209 |
Oh, right, I mean 1209 version. |
Just upgrade postgres driver to v9.4.1209 in brach https://github.com/tminglei/slick-pg/tree/next. Thanks! |
@tminglei I can't use the driver from the next branch because it breaks all of the code, however I have tried Still get To be more useful, I have debugged the statements and I have this info. The value being parsed is |
Actually figured out the issue, the databse has column type |
Maybe someone can share a public Github test repo so we can try it out? (I don't have a test project set up anymore for this issue). Otherwise I'll see if I can publish something tonight. |
I tested with
And it works! Thank you @tminglei |
@danishin glad to hear that! You're welcome! :-) |
As a work around till the issue is resolved, one can also add https://github.com/tototoshi/slick-joda-mapper |
For me, upgrading to |
Hi,
When using joda time with slick-pg I get the following error when reading a record from the database:
Is this a known problem? Seems the database is returning a string without the timezone.
In the database the record is stored as "2015-10-16 15:56:04.041+02"
Thank you
The text was updated successfully, but these errors were encountered: