feedback icon indicating copy to clipboard operation
feedback copied to clipboard

RuntimeError when versions of directly and indirectly imported notebook differ

Open flurrux opened this issue 3 years ago • 4 comments

Describe the bug

sometimes, when the version of a notebook differs across multiple notebooks that depend on it, and those notebooks are imported together, it throws a RuntimeError.
I have entcountered this error multiple times now and had to update the dependencies of each imported notebook to their latest versions to fix it.

To Reproduce

  • make a notebook called math util and add this function: sum = (numArray) => numArray.reduce((p, c) => p + c, 0)

    1  create sum function
  • make another notebook called vector util. import the sum function from math util and lock all dependencies.
    then add this function to vector util: vec2Sum = (vec2Array) => [0, 1].map(i => vec2Array[i]).map(sum)

    2  create vector-sum function
  • open the math util notebook again and rename the sum function to numSum: numSum = (numArray) => numArray.reduce((p, c) => p + c, 0)

    3  rename sum to numSum
  • create another notebook called main and import both vec2Sum and numSum. create a cell that calls vec2Sum: vec2Sum([ [4, 8], [2, 11] ]) get a RuntimeError: sum is not defined

    4  import both functions in another notebook

here is a link to the main-notebook: https://observablehq.com/d/bbbce669a706cd3a?collection=@flurrux/observable-import-error

flurrux avatar Jul 19 '22 09:07 flurrux

Thanks for the detailed report! We will look into it asap.

CobusT avatar Jul 19 '22 16:07 CobusT

We should improve the user experience here, since this can happen with the following steps:

  1. All of the notebooks were private and everything worked
  2. The imports were then locked.
  3. And then more edits were made.
  4. Published all three

Since published notebooks can't import unpublished versions, and the locked versions are unpublished (because after making edits, the version that is published is > the locked version), the import will then fail. This notebook https://observablehq.com/d/77a8cdd5590aed12 has locked this imported notebook at version 10, which is not published: https://observablehq.com/d/7e49ef484449dd9a@10

We should warn users when publishing notebooks that have imports that are locked at private versions to avoid this.

duaneatat avatar Jul 21 '22 20:07 duaneatat

I've repeated the steps and published each version along the way, but the error persists.
here is the new main notebook: https://observablehq.com/d/d7ae020541532e26 the intermediate version of the new math-util is now public: https://observablehq.com/d/e9306e44623d5a81@10

flurrux avatar Jul 21 '22 21:07 flurrux

I see the issue now, thanks so much for your patience on this.

The problem is actually that, with the way that we have implemented Version locking, it's not possible to import vec2Sum from the vector util without getting an error. The reason is that, at the time of import, we ignore the locked versions of the imported notebook. So you end up indirectly importing the latest version of the math util notebook, which is incompatible with the vector util notebook.

vector util imports sum from math util, locking math util at version 10 (which exports the sum) cell.

When you import vec2Sum from vector util, we get the latest version of all direct and indirect imports, and ignore the locked versions in vector util, so you end up indirectly importing math util at the latest version, which doesn't export sum and is incompatible with vector util.

Here is a notebook that reproduces the issue without needing multiple imports: https://observablehq.com/d/3560bc755a254c3a

This behavior was the subject of a lot of internal debate, and I'll raise this issue again internally to see what we can do to help in this circumstance.

In the meantime, the only recourse you have is to update the vector util notebook so it imports the latest version of math util (and fix the incompatibility there).

Thanks for raising this issue, I will update here with any progress we make 🙏

duaneatat avatar Jul 22 '22 03:07 duaneatat