MagicStack / MagicStack/asyncpg

copy_from_query drops headers if any postgis NOTICE/LOCATION messages produced

Đang mở
#1,264 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Python
Star
8.1k
Fork
468
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

when using `Connection.copy_from_query` I had a statement which eventually resolved to something like:
```sql
COPY (
select 1
from field_year_crop_variety_layer fycvl
cross join filters
join field_meta fm on
fm.field_id = fycvl.field_id and
(filters.filter_geometry is null or st_intersects(filters.filter_geometry, fm.centroid))
order by fycvl.field_id, fycvl.harvest_year, fycvl.layer_id, fycvl.crop, fycvl.variety
limit '100000'::int
) TO STDOUT (FORMAT 'csv', HEADER True)
```

where `filter_geometry` is a `geometry`, and `fm.centroid` is a `geography`.

and no matter what I did asyncpg would not return the headers. It wasn't until I broke it down and ran it from psql that I noticed the output:
```
field_id,harvest_year,layer_id,crop,variety,is_precision_data,date_period,avg_date,data_is_missing,missing_data_message,crop_variety_layer_area_m2,geometry,computed_at
NOTICE: 00000: Coordinate values were coerced into range [-180 -90, 180 90] for GEOGRAPHY
LOCATION: geography_from_geometry, geography_inout.c:510
NOTICE: 00000: Coordinate values were coerced into range [-180 -90, 180 90] for GEOGRAPHY
LOCATION: geography_from_geometry, geography_inout.c:510
143011,2017,0,corn,unknown,t,"[2017-04-25,2017-04-26)",2017-04-24,f,,7240.833,,1752130305.616610
```

sure enough, if I fixed the bug (casting fm.centroid to a geometry) the headers appeared. This seems like a bug in asyncpg when interpreting the data returned.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với Connection.copy_from_query và tái hiện truy vấn COPY được cung cấp trên PostgreSQL với các thông báo NOTICE/LOCATION của PostGIS được bật. Theo dõi cách các thông báo đó được xử lý cùng với đầu ra COPY; hoàn tất khi dữ liệu được trả về vẫn giữ tiêu đề CSV trong trường hợp các thông báo như vậy được tạo ra.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
postgresql, python
Lĩnh vực
databases
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.