# Revise.jl bug when updating a package (on Windows)

**URL:** <https://discourse.julialang.org/t/revise-jl-bug-when-updating-a-package-on-windows/85941>\
**Category:** General Usage\
**Created:** [August 18, 2022, 6:57pm UTC](https://discourse.julialang.org/t/revise-jl-bug-when-updating-a-package-on-windows/85941 "2022-08-18T18:57:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brad\_Carman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brad_carman/32/17631_2.png) [@Brad\_Carman](https://discourse.julialang.org/u/Brad_Carman)\
**Post date:** [August 18, 2022, 6:57pm UTC](https://discourse.julialang.org/t/revise-jl-bug-when-updating-a-package-on-windows/85941/1 "2022-08-18T18:57:46Z")

</div>

If I run `pkg"update PkgA"` when I already have `PkgA` loaded, is there anyway to ask Revise to start using the new version?

---

<div class="post-metadata">

**Author:** ![Brad\_Carman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brad_carman/32/17631_2.png) [@Brad\_Carman](https://discourse.julialang.org/u/Brad_Carman)\
**Post date:** [September 6, 2022, 10:40pm UTC](https://discourse.julialang.org/t/revise-jl-bug-when-updating-a-package-on-windows/85941/2 "2022-09-06T22:40:30Z")

</div>

Note: My question is related to using a normally installed package, not a developed package. I suppose Revise.jl doesn’t cover this case. But I feel like it could?

I’ve tried running `pkg"develop PkgA"` after `PkgA` is loaded, but I can’t get the new code to load. If Julia has loaded a package, it seems to be stuck to that code.

---

<div class="post-metadata">

**Author:** ![mfiano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mfiano/32/37565_2.png) [@mfiano](https://discourse.julialang.org/u/mfiano)\
**Post date:** [September 6, 2022, 10:44pm UTC](https://discourse.julialang.org/t/revise-jl-bug-when-updating-a-package-on-windows/85941/3 "2022-09-06T22:44:11Z")

</div>

I don’t know too much about this subject, but I do know that Revise.jl tracks changes to files in a project. That is, you will not see changes until the file is edited and saved, and the REPL is invoked with a usage of that new definition. The REPL invocation is what triggers the recompilation, so nothing happens “automatically” without utilizing Revise.jl’s exposed functionality and rolling your own solution.

Edit: Packages that aren’t `dev`’d live in the depot path and are read-only, so you are correct that you need to `dev` the new package at the very least, because changes must be made to the project before REPL invocations to the new functionality.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 7, 2022, 10:33am UTC](https://discourse.julialang.org/t/revise-jl-bug-when-updating-a-package-on-windows/85941/4 "2022-09-07T10:33:53Z")

</div>

Revise already works when updating a package. Here is an example:

I created this branch on a package [Comparing master...kc/update · KristofferC/Crayons.jl · GitHub](https://github.com/KristofferC/Crayons.jl/compare/master...kc/update)

I then add the package (which will use the registered version)

```julia
pkg> activate --temp
  Activating new project at `/tmp/jl_5GpJ8l`

(jl_5GpJ8l) pkg> add Crayons
    Updating registry at `~/.julia/registries/General.toml`
   Resolving package versions...
    Updating `/tmp/jl_5GpJ8l/Project.toml`
  [a8cc5b0e] + Crayons v4.1.1
    Updating `/tmp/jl_5GpJ8l/Manifest.toml`
  [a8cc5b0e] + Crayons v4.1.1

julia> using Revise, Crayons

julia> Crayons.new_method
ERROR: UndefVarError: new_method not defined

```

Now, I add the branch and Revise will trigger and make the new method available:

```julia
(jl_5GpJ8l) pkg> add Crayons#kc/update
     Cloning git-repo `https://github.com/KristofferC/Crayons.jl.git`
    Updating git-repo `https://github.com/KristofferC/Crayons.jl.git`
   Resolving package versions...
    Updating `/tmp/jl_5GpJ8l/Project.toml`
  [a8cc5b0e] ~ Crayons v4.1.1 ⇒ v4.1.1 `https://github.com/KristofferC/Crayons.jl.git#kc/update`
    Updating `/tmp/jl_5GpJ8l/Manifest.toml`
  [a8cc5b0e] ~ Crayons v4.1.1 ⇒ v4.1.1 `https://github.com/KristofferC/Crayons.jl.git#kc/update`

julia> Crayons.new_method()
Hello, thanks for Revising me

```

---

<div class="post-metadata">

**Author:** ![Brad\_Carman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brad_carman/32/17631_2.png) [@Brad\_Carman](https://discourse.julialang.org/u/Brad_Carman)\
**Post date:** [September 7, 2022, 11:54am UTC](https://discourse.julialang.org/t/revise-jl-bug-when-updating-a-package-on-windows/85941/5 "2022-09-07T11:54:16Z")

</div>

OK, thanks for that example. The case I’m describing is just a simple update, let me describe my problem with a MWE, this case does not work…

```julia
using Revise, Pkg, Test
Pkg.activate(; temp=true)
Pkg.add(name="Crayons", version="1.0.0")

using Crayons
path_1_0_0 = methods(Crayons.print_logo)[1].file

Pkg.update("Crayons")
revise(Crayons)
path_update = methods(Crayons.print_logo)[1].file

# Ensure that we are now pointing to the new code (i.e. v1.0.0 path should be different from updated)
@test path_1_0_0 != path_update

```

This test does not pass…

```julia
Test Failed
  Expression: path_1_0_0 != path_update
   Evaluated: var"C:\\Users\\CarmanBr\\.julia\\packages\\Crayons\\U4Pig\\src\\logo.jl" != var"C:\\Users\\CarmanBr\\.julia\\packages\\Crayons\\U4Pig\\src\\logo.jl"

```

After the update, `path_update` is not changed, Julia is still using the v1.0.0 code, even though I updated the package.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 7, 2022, 12:07pm UTC](https://discourse.julialang.org/t/revise-jl-bug-when-updating-a-package-on-windows/85941/6 "2022-09-07T12:07:46Z")

</div>

> [@Brad\_Carman](#):
>
> Julia is still using the v1.0.0 code, even though I updated the package.

That function was not changed so it is not surprising that nothing has changed with that function. The way Revise works is that it checks for updates to functions and re-evaluates them.

Here is another example where I add a package version with a known bug ([knn: skipped items output when there is a skip function has always the last index and not 0 index · Issue #145 · KristofferC/NearestNeighbors.jl · GitHub](https://github.com/KristofferC/NearestNeighbors.jl/issues/145)), update it to a working version and see that the bug if fixed. The path is also updated:

```julia
❯ julia --check-bounds=yes -q

(@v1.8) pkg> activate --temp
Activating new project at `/tmp/jl_iyvOZH`

(jl_iyvOZH) pkg> add NearestNeighbors@0.4.10
    Updating registry at `~/.julia/registries/General.toml`
   Resolving package versions...
    Updating `/tmp/jl_iyvOZH/Project.toml`
⌃ [b8a86587] + NearestNeighbors v0.4.10
    Updating `/tmp/jl_iyvOZH/Manifest.toml`
  [b4f34e82] + Distances v0.10.7
⌃ [b8a86587] + NearestNeighbors v0.4.10
  [90137ffa] + StaticArrays v1.5.6
...
        Info Packages marked with ⌃ have new versions available

julia> using Revise, NearestNeighbors

julia> data = [[0.13380863416387367, 0.7845254987714512],[0.1563342025559629, 

julia> tree = KDTree(hcat(map(p -> [p[1], p[2]], data)...));

julia> nearest, distance = knn(tree, [0.15, 0.8], 3, true, x -> x == 2) # buggy behavior
ERROR: BoundsError: attempt to access 3-element Vector{Int64} at index [-1]
Stacktrace:
 [1] getindex
   @ ./array.jl:924 [inlined]
 [2] knn_point!(tree::KDTree{StaticArraysCore.SVector{2, Float64}, Euclidean, Float64}, point::Vector{Float64}, sortres::Bool, dist::Vector{Float64}, idx::Vector{Int64}, skip::var"#5#6")
   @ NearestNeighbors ~/.julia/packages/NearestNeighbors/YCcEC/src/knn.jl:36
 [3] knn(tree::KDTree{StaticArraysCore.SVector{2, Float64}, Euclidean, Float64}, point::Vector{Float64}, k::Int64, sortres::Bool, skip::var"#5#6")
   @ NearestNeighbors ~/.julia/packages/NearestNeighbors/YCcEC/src/knn.jl:46
 [4] top-level scope
   @ REPL[6]:1

julia> @which knn(tree, [0.15, 0.8], 3, true, x -> x == 2)
knn(tree::NNTree{V}, point::AbstractVector{T}, k::Int64, sortres, skip::F) where {V, T<:Number, F<:Function} in NearestNeighbors at /home/kc/.julia/packages/NearestNeighbors/YCcEC/src/knn.jl:42

(jl_iyvOZH) pkg> update    
    Updating `/tmp/jl_iyvOZH/Project.toml`
  [b8a86587] ↑ NearestNeighbors v0.4.10 ⇒ v0.4.11
    Updating `/tmp/jl_iyvOZH/Manifest.toml`
  [b8a86587] ↑ NearestNeighbors v0.4.10 ⇒ v0.4.11

julia> nearest, distance = knn(tree, [0.15, 0.8], 3, true, x -> x == 2) # bug is fixed
([1, 3], [0.02239688629947563, 0.13440059522389006])

julia> @which knn(tree, [0.15, 0.8], 3, true, x -> x == 2) # new path
knn(tree::NNTree{V}, point::AbstractVector{T}, k::Int64, sortres, skip::F) where {V, T<:Number, F<:Function} in NearestNeighbors at /home/kc/.julia/packages/NearestNeighbors/VZzTb/src/knn.jl:47
```

---

<div class="post-metadata">

**Author:** ![Brad\_Carman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brad_carman/32/17631_2.png) [@Brad\_Carman](https://discourse.julialang.org/u/Brad_Carman)\
**Post date:** [September 7, 2022, 12:47pm UTC](https://discourse.julialang.org/t/revise-jl-bug-when-updating-a-package-on-windows/85941/7 "2022-09-07T12:47:02Z")

</div>

OK, I cannot reproduce your MWE. I get an error still after updating NearestNeighbors.

My version of Julia is v1.8.0-rc3 on Windows 10 and I’m using Revise v3.4.0

Script…

```julia
using Revise, Pkg, Test
Pkg.activate(; temp=true)
Pkg.add(name="NearestNeighbors", version="0.4.10")

using NearestNeighbors
data = [[0.13380863416387367, 0.7845254987714512],[0.1563342025559629, 0.],[0.563342025559629, 0.7]]
tree = KDTree(hcat(map(p -> [p[1], p[2]], data)...));

println(":: current path ==> $(which(knn, typeof.((tree, [0.15, 0.8], 3, true, x -> x == 2))).file)")
@test_throws BoundsError knn(tree, [0.15, 0.8], 3, true, x -> x == 2) # buggy behavior

Pkg.update("NearestNeighbors")
revise(NearestNeighbors)

println(":: updated path ==> $(which(knn, typeof.((tree, [0.15, 0.8], 3, true, x -> x == 2))).file)")
nearest, distance = knn(tree, [0.15, 0.8], 3, true, x -> x == 2)

```

Here is my full output…

```julia
> julia --check-bounds=yes -q -i test2.jl
  Activating new project at `C:\Users\CarmanBr\AppData\Local\Temp\jl_UgBJAS`
    Updating registry at `C:\Users\CarmanBr\.julia\registries\CatapultApps`
    Updating git-repo `https://ist-catapult.visualstudio.com/DefaultCollection/CatapultApps/_git/Registry`
    Updating registry at `C:\Users\CarmanBr\.julia\registries\General.toml`
   Resolving package versions...
    Updating `C:\Users\CarmanBr\AppData\Local\Temp\jl_UgBJAS\Project.toml`
⌃ [b8a86587] + NearestNeighbors v0.4.10
    Updating `C:\Users\CarmanBr\AppData\Local\Temp\jl_UgBJAS\Manifest.toml`
  [b4f34e82] + Distances v0.10.7
⌃ [b8a86587] + NearestNeighbors v0.4.10
  [90137ffa] + StaticArrays v1.5.6
  [1e83bf80] + StaticArraysCore v1.3.0
  [82ae8749] + StatsAPI v1.5.0
  [56f22d72] + Artifacts
  [8f399da3] + Libdl
  [37e2e46d] + LinearAlgebra
  [9a3f8284] + Random
  [ea8e919c] + SHA v0.7.0
  [9e88b42a] + Serialization
  [2f01184e] + SparseArrays
  [10745b16] + Statistics
  [e66e0078] + CompilerSupportLibraries_jll v0.5.2+0
  [4536629a] + OpenBLAS_jll v0.3.20+0
  [8e850b90] + libblastrampoline_jll v5.1.1+0
        Info Packages marked with ⌃ have new versions available
:: current path ==> C:\Users\CarmanBr\.julia\packages\NearestNeighbors\YCcEC\src\knn.jl
    Updating registry at `C:\Users\CarmanBr\.julia\registries\CatapultApps`
    Updating git-repo `https://ist-catapult.visualstudio.com/DefaultCollection/CatapultApps/_git/Registry`
    Updating registry at `C:\Users\CarmanBr\.julia\registries\General.toml`
    Updating `C:\Users\CarmanBr\AppData\Local\Temp\jl_UgBJAS\Project.toml`
  [b8a86587] ↑ NearestNeighbors v0.4.10 ⇒ v0.4.11
    Updating `C:\Users\CarmanBr\AppData\Local\Temp\jl_UgBJAS\Manifest.toml`
  [b8a86587] ↑ NearestNeighbors v0.4.10 ⇒ v0.4.11
:: updated path ==> C:\Users\CarmanBr\.julia\packages\NearestNeighbors\YCcEC\src\knn.jl
ERROR: LoadError: BoundsError: attempt to access 3-element Vector{Int64} at index [-1]
Stacktrace:
 [1] getindex
   @ .\array.jl:924 [inlined]
 [2] knn_point!(tree::KDTree{StaticArraysCore.SVector{2, Float64}, Euclidean, Float64}, point::Vector{Float64}, sortres::Bool, dist::Vector{Float64}, idx::Vector{Int64}, skip::var"#9#10")      
   @ NearestNeighbors C:\Users\CarmanBr\.julia\packages\NearestNeighbors\YCcEC\src\knn.jl:36
 [3] knn(tree::KDTree{StaticArraysCore.SVector{2, Float64}, Euclidean, Float64}, point::Vector{Float64}, k::Int64, sortres::Bool, skip::var"#9#10")
   @ NearestNeighbors C:\Users\CarmanBr\.julia\packages\NearestNeighbors\YCcEC\src\knn.jl:46
 [4] top-level scope
   @ C:\Work\IST\Projects\JuliaPackages\BuildAndBenchmark.jl\test2.jl:16

```

---

<div class="post-metadata">

**Author:** ![Brad\_Carman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brad_carman/32/17631_2.png) [@Brad\_Carman](https://discourse.julialang.org/u/Brad_Carman)\
**Post date:** [September 7, 2022, 3:37pm UTC](https://discourse.julialang.org/t/revise-jl-bug-when-updating-a-package-on-windows/85941/8 "2022-09-07T15:37:13Z")

</div>

It seems we have a bug here. Going to post an issue to Revise.jl. I tested on 3 different Windows PC’s all give the same result. It seems to work on Linux.
