-
-
Notifications
You must be signed in to change notification settings - Fork 246
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
Unknown type Jsonb when using Attributes API. #267
Comments
If I load this class from AR master and register it with |
Thanks for reporting this issue. This adapter is a subclass of the Postgres adapter: I'm not sure what the cause of the problem is, but maybe that will help. |
Hey thanks for the tip (and the gem). I'll try more debugging this afternoon. |
Hey @teeparham. I think I've found the issue, not sure how you'd like to go about resolving it in your adapter. The postgresql adapter registers these native types specific to the postgres adapter as such:
I've found by registering these with the adapter set to postgis, the problem goes away.
I guess you could just duplicate the registrations in the PostGIS connection adapter. It's unlikely they'll suffer from a ton of churn. It would be a lot nicer maintenance wise if you could read metadata from the PostgreSQL registry and repeat them for PostGIS adapter. Not exactly sure how to do that but going to poke around. This is deeper than I've had to go before in AR ;) If I find a nice solution I'll issue a PR for you |
I couldn't find a way to read decent way to read the registry and get the collection of types initialized in |
I still don't have a solution but here's what I found/confirmed: The types are registered to the "postgresql" adapter (even though we're using "postgis"). New spatial types are not registered. Ideally the upstream type registration in the PostgreSQLAdapater would work for subclassed adapters, & then the PostGIS adapter could add the new spatial types. # ActiveRecord 5.0
ActiveRecord::Type.registry.send(:registrations).map{|r| [r.send(:adapter), r.send(:name)].join(" : ")}
[
[ 0] " : big_integer",
[ 1] " : binary",
[ 2] " : boolean",
[ 3] " : date",
[ 4] " : datetime",
[ 5] " : decimal",
[ 6] " : float",
[ 7] " : integer",
[ 8] " : string",
[ 9] " : text",
[10] " : time",
[11] "postgresql : ",
[12] "postgresql : ",
[13] "postgresql : bit",
[14] "postgresql : bit_varying",
[15] "postgresql : binary",
[16] "postgresql : cidr",
[17] "postgresql : datetime",
[18] "postgresql : decimal",
[19] "postgresql : enum",
[20] "postgresql : hstore",
[21] "postgresql : inet",
[22] "postgresql : json",
[23] "postgresql : jsonb",
[24] "postgresql : money",
[25] "postgresql : point",
[26] "postgresql : legacy_point",
[27] "postgresql : uuid",
[28] "postgresql : vector",
[29] "postgresql : xml" It seems possible to alter the type registry when the PostGIS adapter is loaded (change "postgresql" to "postgis"). For example, this hackery works: ActiveRecord::Type.registry.send(:registrations).last.instance_variable_set("@adapter", "postgis") |
Yeah. For now I’ve just copied the registrations from the Postgres get rather than try to do it dynamically. I’m loading them via an initializer.
FWIW, the set is so infrequently changed it may be worth just registering these types manually and doing a point release when something new comes along (or goes away).
…Sent from my iPhone
On Dec 12, 2017, at 11:28 AM, Tee Parham ***@***.***> wrote:
I still don't have a solution but here's what I found/confirmed:
The types are registered to the "postgresql" adapter (even though we're using "postgis"). New spatial types are not registered. Ideally the upstream type registration in the PostgreSQLAdapater would work for subclassed adapters, & then the PostGIS adapter could add the new spatial types.
# ActiveRecord 5.0
ActiveRecord::Type.registry.send(:registrations).map{|r| [r.send(:adapter), r.send(:name)].join(" : ")}
[
[ 0] " : big_integer",
[ 1] " : binary",
[ 2] " : boolean",
[ 3] " : date",
[ 4] " : datetime",
[ 5] " : decimal",
[ 6] " : float",
[ 7] " : integer",
[ 8] " : string",
[ 9] " : text",
[10] " : time",
[11] "postgresql : ",
[12] "postgresql : ",
[13] "postgresql : bit",
[14] "postgresql : bit_varying",
[15] "postgresql : binary",
[16] "postgresql : cidr",
[17] "postgresql : datetime",
[18] "postgresql : decimal",
[19] "postgresql : enum",
[20] "postgresql : hstore",
[21] "postgresql : inet",
[22] "postgresql : json",
[23] "postgresql : jsonb",
[24] "postgresql : money",
[25] "postgresql : point",
[26] "postgresql : legacy_point",
[27] "postgresql : uuid",
[28] "postgresql : vector",
[29] "postgresql : xml"
It seems possible to alter the type registry when the PostGIS adapter is loaded (change "postgresql" to "postgis"). For example, this hackery works:
***@***.***", "postgis")
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
With #334, the adapter will now check for types registered under the |
yay!
…On Thu, Mar 4, 2021 at 9:35 AM Keith Doggett ***@***.***> wrote:
With #334 <#334>,
the adapter will now check for types registered under the :postgis or
:postgresql adapters.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#267 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABIZMNKTTWYIC6MUSMV5B3TB6SEJANCNFSM4ECOIVSA>
.
|
@keithdoggett has there been a new release since that was merged? I just ran into this in combination with another gem (that relies on type lookups) not being able to find type |
Even just throwing the types registration into an override module fixes it for me though, so the fix is definitely functional! just either waiting on or missed the next release |
@SampsonCrowley this has been released in 7.1.0 and is only in the master branch currently. |
Hi.
I'm having an issue when declaring a jsonb attribute using the attributes api and the postgis adapter. This works fine when using the
postgresql
adapter.If I have a model defined like this
I get the following error in rails console
Note the 2nd call doesn't fail, although the model does not have the
foobar
attribute defined on it.I've created a sample app here to recreate the problem. I tried to dig through this and the
pg
gem to see the difference in how theActiveRecord::Type
s are registered, but couldn't figure it out. I'll continue to search on my own but wanted to open an issue on it for now.https://github.com/jhirn/postgis_jsonb_attribute_bug/blob/master/README.md
The text was updated successfully, but these errors were encountered: