Repository: astral-sh/uv
File: crates/uv-resolver/src/candidate_selector.rs (Rust)

Code before:
                    }
                    // We do not consider installed distributions with multiple versions because
                    // during installation these must be reinstalled from the remote
                    _ => {
                        debug!(
                            "Ignoring installed versions of {package_name}: multiple distributions found"
                        );
                    }
                }
            }

            // Respect the pre-release strategy for this fork.
            if version.any_prerelease() {
                let allow = match self.prerelease_strategy.allows(package_name, env) {
                    AllowPrerelease::Yes => true,
                    AllowPrerelease::No => false,
                    // If the pre-release is "global", i.e., it comes from a solve without a fork,
                    // or is provided via a lockfile, accept it unless pre-releases are completely
                    // banned.
                    AllowPrerelease::IfNecessary => match source {
                        PreferenceSource::Fork => false,
                        PreferenceSource::Lock
                        | PreferenceSource::Environment
                        | PreferenceSource::Resolve
                        | PreferenceSource::RequirementsTxt => true,
                    },
                };
                if !allow {
                    continue;
                }
            }

            // Check for a remote distribution that matches the preferred version
            if let Some((version_map, file)) = version_maps
                .iter()
                .find_map(|version_map| version_map.get(version).map(|dist| (version_map, dist)))
            {
                // If the preferred version has a local variant, prefer that.
                if version_map.local() {
                    for local in version_map
                        .versions()
                        .rev()
                        .take_while(|local| *local > version)
                    {
                        if !local.is_local() {
                            continue;
                        }
                        if local.clone().without_local() != *version {
                            continue;
                        }
                        if !range.contains(local) {

Review comment (suggestion):
This is the crux of the change. I believe relying on `marker.is_true()` to determine if we should respect a preference was fallible for cases where the preference came an existing fork in the lockfile with markers attatched.

Code after:
                    }
                    // We do not consider installed distributions with multiple versions because
                    // during installation these must be reinstalled from the remote
                    _ => {
                        debug!(
                            "Ignoring installed versions of {package_name}: multiple distributions found"
                        );
                    }
                }
            }

            // Respect the pre-release strategy for this fork.
            if version.any_prerelease() {
                let allow = match self.prerelease_strategy.allows(package_name, env) {
                    AllowPrerelease::Yes => true,
                    AllowPrerelease::No => false,
                    // If the pre-release was provided via an existing file, rather than from the
                    // current solve, accept it unless pre-releases are completely banned.
                    AllowPrerelease::IfNecessary => match source {
                        PreferenceSource::Resolver => false,
                        PreferenceSource::Lock
                        | PreferenceSource::Environment
                        | PreferenceSource::RequirementsTxt => true,
                    },
                };
                if !allow {
                    continue;
                }
            }

            // Check for a remote distribution that matches the preferred version
            if let Some((version_map, file)) = version_maps
                .iter()
                .find_map(|version_map| version_map.get(version).map(|dist| (version_map, dist)))
            {
                // If the preferred version has a local variant, prefer that.
                if version_map.local() {
                    for local in version_map
                        .versions()
                        .rev()
                        .take_while(|local| *local > version)
                    {
                        if !local.is_local() {
                            continue;
                        }
                        if local.clone().without_local() != *version {
                            continue;
                        }
                        if !range.contains(local) {
                            continue;
                        }