Skip to content

Commit

Permalink
Handle exception when timezone is localtime (#2264)
Browse files Browse the repository at this point in the history
The configuration property `timezone` in `postgresql.conf` can be
set to a special value of `localtime` to indicate that PosgreSQL
should use the timezone of the host system.

Unfortunately, when this value is set, we do not have sufficient
information to determine the actual timezone of the server because
`SHOW timezone` itself returns `localtime`.

This value is not well-documented, but is also unlikely to be
encountered very often, so we identify the exception and construct
a new `TimeZoneNotFoundException` with a more informative
message that includes mitigations that can be applied on either
the server or the client.

See: npgsql/efcore.pg#578
  • Loading branch information
austindrenski committed Dec 22, 2018
1 parent f60e2a0 commit 140c1b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions Npgsql.sln.DotSettings
Expand Up @@ -82,6 +82,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Noda/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Noda/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Npgsql/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Npgsql/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Npgsql_0027s/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Npgsql_0027s/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=PGTZ/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Postgre/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Postgre/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=P_0020keepaliv/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=P_0020keepaliv/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=resultset/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=resultset/@EntryIndexedValue">True</s:Boolean>
Expand Down
9 changes: 8 additions & 1 deletion src/Npgsql.NodaTime/TimestampTzHandler.cs
Expand Up @@ -93,7 +93,14 @@ ZonedDateTime INpgsqlSimpleTypeHandler<ZonedDateTime>.Read(NpgsqlReadBuffer buf,
return TimestampHandler.Decode(value).InZone(_dateTimeZoneProvider[buf.Connection.Timezone]); return TimestampHandler.Decode(value).InZone(_dateTimeZoneProvider[buf.Connection.Timezone]);
} }
} }
catch (DateTimeZoneNotFoundException e) catch (TimeZoneNotFoundException) when (string.Equals(buf.Connection.Timezone, "localtime", StringComparison.OrdinalIgnoreCase))
{
throw new NpgsqlSafeReadException(
new TimeZoneNotFoundException(
"The special PostgreSQL timezone 'localtime' is not supported when reading values of type 'timestamp with time zone'. " +
"Please specify a real timezone in 'postgresql.conf' on the server, or set the 'PGTZ' environment variable on the client."));
}
catch (TimeZoneNotFoundException e)
{ {
throw new NpgsqlSafeReadException(e); throw new NpgsqlSafeReadException(e);
} }
Expand Down

0 comments on commit 140c1b4

Please sign in to comment.