Skip to content

git branch based dependency causes panic #389

@houqp

Description

@houqp

Please provide the following information:

  • Your python version (python -V): Python 3.7.9
  • Your pip version (pip -V): pip 20.2.4
  • The version of the bindings you're using, if any (e.g. pyo3, rust-cpython or cffi): pyo3
  • Does cargo build work? no
  • If on windows, have you checked that you aren't accidentally using unix path (those with the forward slash /)?

Please list the exact steps required to reproduce your error with all command output and if possible with a repository:

  1. in Cargo.toml, define a dependency using git branch as source, for example: arrow = { git = "https://github.com/apache/arrow.git", branch = "master" }
  2. run maturin develop

Panic with the follow stack trace:

name = 'maturin'
operating_system = 'unix:OSX'
crate_version = '0.9.0-beta.1'
explanation = '''
Panic occurred in file '/Users/qph/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo_metadata-0.12.1/src/lib.rs' at line 168
'''
cause = 'no package with this id: PackageId { repr: "arrow 3.0.0-SNAPSHOT (git+https://github.com/apache/arrow.git#6c3547347e9d95f7d0c77d5949cb8fcf6983ca9b)" }'
method = 'Panic'
backtrace = '''

   0: 0x1026424ea - rust_begin_unwind
                at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/panicking.rs:483
   1: 0x102689e5b - std::panicking::begin_panic_fmt::h7f8479886aec7328
                at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/panicking.rs:437
   2: 0x1025f7b92 - <cargo_metadata::Metadata as core::ops::index::Index<&cargo_metadata::PackageId>>::index::{{closure}}::h22a069f31383902b
   3: 0x1025f7b3a - <cargo_metadata::Metadata as core::ops::index::Index<&cargo_metadata::PackageId>>::index::h53a9ba61f475a8ed
   4: 0x101f9bbbb - maturin::build_options::BuildOptions::into_build_context::hee37aa98654215e0
   5: 0x101f64084 - maturin::develop::develop::h427e13b207b306f8
   6: 0x101e17269 - maturin::run::h907da620f5efa96d
   7: 0x101e1c80e - maturin::main::h86b5ab6e9ae50611
   8: 0x101e2573a - std::sys_common::backtrace::__rust_begin_short_backtrace::hfb288adc1e2ec0b1
   9: 0x101e2578c - std::rt::lang_start::{{closure}}::h196c5a111fa8c4ea
  10: 0x102642e04 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h9057ea904b35cc05
                at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/core/src/ops/function.rs:259
                 - std::panicking::try::do_call::h1d4ab8154449bcdb
                at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/panicking.rs:381
                 - std::panicking::try::h965145e9828a5ce6
                at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/panicking.rs:345
                 - std::panic::catch_unwind::h654b507ae4f5edb8
                at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/panic.rs:382
                 - std::rt::lang_start_internal::h34f975c4b2f9557d
                at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/rt.rs:51
  11: 0x101e1cb99 - _main'''

The root cause of this bug is because package ids tracked in cargo_metadata.packages are different from cargo_metadata.resolve when package is using git branch as the source. For example:

  • in cargo_metadata.packages, the arrow crate is tracked with package id: "arrow 3.0.0-SNAPSHOT (git+https://github.com/apache/arrow.git?branch=master#6c3547347e9d95f7d0c77d5949cb8fcf6983ca9b)".
  • but in cargo_metadata.resolve, it is tracked as carrow 3.0.0-SNAPSHOT (git+https://github.com/apache/arrow.git#6c3547347e9d95f7d0c77d5949cb8fcf6983ca9b)

Because cargo_metadata's index implementation is doing simple string equality check, it simply panics when the package id from resolve is used as the index: https://github.com/oli-obk/cargo_metadata/blob/596fb658bfa796de3706833a118b6952e6e6be01/src/lib.rs#L167.

Perhaps instead of doing index lookup in build_options::find_bridge, we should implementation our own lookup heuristic to ignore that ?branch=master query string.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions