get_parameter_source does not work with invoke or forward

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

Maintainer thường phản hồi trong vòng 1 ngày

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

  • #3790 của @leilei3167 — đã đóng, không merge

Đánh giá

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

Hướng nghiên cứu

Bắt đầu bằng cách chạy sample với Click 8.1.7 và so sánh get_parameter_source trong các lần gọi trực tiếp, forward và invoke. Theo dõi các điểm vào Context get_parameter_source, forward và invoke để xác định cách các nguồn tham số được phân giải; hoàn thành có nghĩa là các lệnh được invoke báo cáo nguồn mong đợi, với các kiểm thử bao quát cả hai đường dẫn.

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

Mô tả

parsing

When invoking one Click command from another using either invoke or forward, get_parameter_source does not appear to work as it does if the command were called directly.

Sample code:

import click

cli = click.Group()

@cli.command()
@click.option('--count', default=1)
@click.pass_context
def test(ctx, count):
    click.echo(f'Count: {count}')
    click.echo(f'ctx.get_parameter_source: {ctx.get_parameter_source("count")}')
    click.echo(f'ctx.parent.get_parameter_source: {ctx.parent.get_parameter_source("count") if ctx.parent else None}')

@cli.command()
@click.option('--count', default=1)
@click.pass_context
def dist(ctx, count):
    click.echo("Calling directly")
    test(standalone_mode=False)
    click.echo("Forwarding")
    ctx.forward(test)
    click.echo("Invoking")
    ctx.invoke(test, count=42)

if __name__ == '__main__':
    dist()

Results:

Calling directly
Count: 1
ctx.get_parameter_source: ParameterSource.DEFAULT
ctx.parent.get_parameter_source: None
Forwarding
Count: 1
ctx.get_parameter_source: None
ctx.parent.get_parameter_source: ParameterSource.DEFAULT
Invoking
Count: 42
ctx.get_parameter_source: None
ctx.parent.get_parameter_source: ParameterSource.DEFAULT

I would expect ctx.get_parameter_source to be ParameterSource.DEFAULT for the calls made using invoke and forward or for the differing behavior to be explicitly mentioned in the get_parameter_source documentation. I ran into this issue when wrapping a dbt command, so I believe I'm not the only one that expects not to have to check a parent's get_parameter_source (dbt source).

Thank you for your help.

Environment:

  • Python version: Python 3.9.17
  • Click version: 8.1.7
Ngôn ngữ chính
Python
Star
17.8k
Fork
3.3k
Merge trung bình
3 ngày 3 giờ
Pull request đã merge (30 ngày)
13

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

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.

Issue khác của pallets/click

Tất cả issue của pallets/click

Issue tương tự

Thêm issue về Python

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.