microsoft/azuredatastudio-postgresql

object has no attribute 'encode

mstein-IDEX opened this issue ยท 30 comments

Type: Bug

Hello,

when I run the following query I get an error "Unhandled exception while executing query: 'IPv4Address' object has no attribute 'encode'"

select asset_id
,mac_address
,ip_address
from public.dim_asset

Table Schema located here.
https://help.rapid7.com/nexpose/en-us/warehouse/warehouse-schema.html#dim_asset.ip_address

Azure Data Studio version: azuredatastudio 1.45.0 (8eff468100f02157f2219335f7a566d14451ca49, 2023-07-24T18:22:12.106Z)
OS version: Windows_NT x64 10.0.22621
Restricted Mode: No
Preview Features: Enabled
Modes:

System Info
Item Value
CPUs 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz (8 x 1805)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) undefined
Memory (System) 31.73GB (12.51GB free)
Process Argv
Screen Reader no
VM 0%
Extensions (1)
Extension Author (truncated) Version
azuredatastudio-postgresql Mic 0.5.0

@mstein-IDEX

Do you also experience similar error with SSMS 19?

I have not loaded SQL Server Management Studio 19.1 but will this morning.

Update loading now......

Just installed SSMS 19 with azure data studio.

I have the same issues, what else can I test?

image

I meant can you run your query on SSMS and let us know if this issue occurs there too?

So this is a postgres DB, I'll see if it can connect

Oh, sorry I thought this was MSSQL, never mind. I will transfer to PostgreSQL extension repo.

Apologies I have been away any update?

I running into this error as well (when I query tables with IP addresses using steampipe.io)

Version: 1.45.1
Commit: 88c21b1725a3e79440027bdb7b5a55fb036be0e2
Date: 2023-08-03T00:42:36.656Z
VS Code: 1.79.2
Electron: 22.3.14
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Darwin x64 22.5.0

nasc17 commented

We are currently working on solution. We will send update when fix can first be tested from the insiders release.

BTW I also see this issue with PowerBI not sure if it's related.

thanks

nasc17 commented

Bug has been addressed in our unstable release of PostgreSQL extension v0.5.1-insiders. We would appreciate your verification that it has been handled appropriately.

I loaded the new ARM64 OSX 0.5.1-insiders release, and I cannot connect to any database now. I getting this error:

image

Here's what I have in the logs:

[Error - 2:49:37 PM] Starting client failed
Launching server using command /Users/caioergos/.azuredatastudio/extensions/microsoft.azuredatastudio-postgresql-0.5.1/out/ossdbtoolsservice/OSX_ARM64/v1.9.1-insiders/pgsqltoolsservice/ossdbtoolsservice_main failed.
nasc17 commented

Hi @caioeps , we discovered an issue with the ARM executable for insiders. Please revert back to our current stable release until we are able resolve this problem.

nasc17 commented

@caioeps the unstable release has been updated. Please inform us if same connection issue presents itself: https://github.com/microsoft/azuredatastudio-postgresql/releases/tag/v0.5.1-insiders

@nasc17 Yeah, unfortunately the error persists.

[Error - 11:02:38 PM] Starting client failed
Launching server using command /Users/caioergos/.azuredatastudio/extensions/microsoft.azuredatastudio-postgresql-0.5.1/out/ossdbtoolsservice/OSX_ARM64/v1.9.1-insiders/pgsqltoolsservice/ossdbtoolsservice_main failed.
nasc17 commented

@nasc17 Yeah, unfortunately the error persists.

[Error - 11:02:38 PM] Starting client failed
Launching server using command /Users/caioergos/.azuredatastudio/extensions/microsoft.azuredatastudio-postgresql-0.5.1/out/ossdbtoolsservice/OSX_ARM64/v1.9.1-insiders/pgsqltoolsservice/ossdbtoolsservice_main failed.

Hi, thanks for the quick response.

There have been some new binaries introduced in the insiders build, and we suspect they may be related to the issue. Could you please follow the steps below to clean up your environment?

Navigate to "C:\Users<user_name>.azuredatastudio\extensions" and delete any existing PostgreSQL extensions. Don't worry about losing your connection information, as they will reappear once you reinstall the extension.

Open your file explorer and go to the "%temp%" location. Remove any folders named "_MEI<6digit number>" if they exist.

Once you have completed these steps, please try downloading and installing the 0.5.1-insiders vsix of the PostgreSQL extension again.

Please let us know if this resolves the issue or if you need any further assistance.

Additional error logging you can check:
C:\Users<user_name>\AppData\Roaming\azuredatastudio\logs
(esp. C:\Users\daeunyim\AppData\Roaming\azuredatastudio\logs\exthost1)
C:\Users<user_name>\AppData\Roaming\sqlops\pgsql

I was having the same original issue on Windows 10 22H2 with Azure Data Studio's latest builds, both regular and insider's. The extension of 0.5.0 did not work for either.

0.5.1-insiders works as expected! My queries are running and returning data.

If it matters, I've only tested running locally and using an IP address for the server/host (127.0.0.1).

The extension of 0.5.0 do not working for me either.

nasc17 commented

@gsl-pierrekore could you please provide us more information on how the extension is not working for you? If it does not relate to the original issue of this post, you can file a separate one for us to review.

Thank you

I am using extension version 0.5.1 and am still seeing this issue or what appears to be the same issue. Thank you.
image

image

I found a workaround for this. The problem is ADS knows knows how to process basic encodings like integer (number,int,bigint,etc.) or string (varchar,etc.), there maybe more but I don't know what they are (maybe date and time?).

Encodings like CIDR causes problems. I can only assume your ip_address is an encoding that is not a varcahr. I am guessing there wasn't any logic put in place for ADS to process Postgres CIDR encodings.

You can add ::TEXT at the end of each attribute you are querying with an encoding type that ADS does not recognize (i.e. CIDR). Doing this will force ADS to convert the encoding to a string before presenting. From your example I would do the following.

select asset_id
,mac_address
,ip_address::TEXT
from public.dim_asset

Can you confirm if this helped? I bet you could do the same for other encoding types that ADS does not understand.

I would recommend ADS put this in their documentation because it is not obvious.
More so, I'd like to recommend ADS do this conversion for us so we don't have to. This application presents data, so obviously we want any weird encodings to be converted to strings for presentation.

Any ETA on this?

nasc17 commented

image

I found a workaround for this. The problem is ADS knows knows how to process basic encodings like integer (number,int,bigint,etc.) or string (varchar,etc.), there maybe more but I don't know what they are (maybe date and time?).

Encodings like CIDR causes problems. I can only assume your ip_address is an encoding that is not a varcahr. I am guessing there wasn't any logic put in place for ADS to process Postgres CIDR encodings.

You can add ::TEXT at the end of each attribute you are querying with an encoding type that ADS does not recognize (i.e. CIDR). Doing this will force ADS to convert the encoding to a string before presenting. From your example I would do the following.

select asset_id
,mac_address
,ip_address::TEXT
from public.dim_asset

Can you confirm if this helped? I bet you could do the same for other encoding types that ADS does not understand.

I would recommend ADS put this in their documentation because it is not obvious. More so, I'd like to recommend ADS do this conversion for us so we don't have to. This application presents data, so obviously we want any weird encodings to be converted to strings for presentation.

Could you please also add what datatypes were you using in this table?
I suspect this is due to macaddr8 array type?

I tested with this dummy table.
CREATE TABLE network_data_extensive (
id SERIAL PRIMARY KEY,
ip_address inet,
ip_address_array inet[],
subnet cidr,
subnet_array cidr[],
mac_address_standard macaddr,
mac_address_extended macaddr8,
mac_address_standard_array macaddr[],
mac_address_extended_array macaddr8[]
);

Running query on this table works with the existing version except for macaddr8[] datatype. I'll add macaddr8[] in the upcoming PR.

@DaeunYim

Could you please also add what datatypes were you using in this table?

I already did in my post, see above

Encodings like CIDR causes problems. I can only assume your ip_address is an encoding that is not a varcahr. I am guessing there wasn't any logic put in place for ADS to process Postgres CIDR encodings.

Datatypes are cidr.

I dont use macaddr or macaddr8.

@DaeunYim

Could you please also add what datatypes were you using in this table?

I already did in my post, see above

Encodings like CIDR causes problems. I can only assume your ip_address is an encoding that is not a varcahr. I am guessing there wasn't any logic put in place for ADS to process Postgres CIDR encodings.

Datatypes are cidr.

I dont use macaddr or macaddr8.

Hi, I don't see any issue with CIDR data type. Can you update the extension if there's any newer version?

I tested out these different ip address values in the above column. I'll try to check what I can possibly have missed.

'192.168.1.1'
'192.168.1.1/24'
'2001:db8::1234
'2001:db8::1234/64'

Hi, I don't see any issue with CIDR data type. Can you update the extension if there's any newer version?

I don't know what this means, what do you mean by "update the extension", do you mean update the whole ADS program?

Postgres support in ADS uses the postgres extension. On the side bar is an icon with four squares; when that is active (click it), you should see the list of installed extensions, which should include postgres. Clicking the postgres extension should either bring you to the screen to update or, in my case, tells me a reload is required to enable the new update (I must have auto update enabled).