Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests to ensure that context is properly reset #5083

Merged
merged 5 commits into from
Dec 19, 2023

Conversation

jaimergp
Copy link
Contributor

@jaimergp jaimergp commented Nov 22, 2023

Description

See conda/conda#13357

Checklist - did you ...

  • Add a file to the news directory (using the template) for the next release's release notes?
  • Add / update necessary tests?
  • Add / update outdated documentation?

@conda-bot conda-bot added the cla-signed [bot] added once the contributor has signed the CLA label Nov 22, 2023
@mbargull
Copy link
Member

I'll also submit a PR to add a test case (using the add_pip_as_python_dependency: false as an example we can easily check).

@jaimergp jaimergp closed this Nov 22, 2023
@jaimergp jaimergp reopened this Nov 22, 2023
@jaimergp
Copy link
Contributor Author

Awesome! Feel free to push here if you want @mbargull!

@mbargull mbargull force-pushed the try-context-no-default branch 8 times, most recently from dbe734b to 5c63e3f Compare November 23, 2023 13:43
@mbargull
Copy link
Member

Sorry for the commit notification spam 🙈 .

So, the added test does not fail although it should...
I don't actually know why (additional caching someplace else? IDK).

My plan was to add that test with an xfail for
context.solver == "libmamba" and VersionSpec("<FUTURE_FIXED_VERSION").match(conda.__version__)
in a new PR.
But it's not failing as expected yet 😞.

@jaimergp
Copy link
Contributor Author

conda-forge/stackvana-feedstock#158 does work though :D

@mbargull
Copy link
Member

conda-forge/stackvana-feedstock#158 does work though :D

Oh, yeah, it definitely fixes the issues.

I just want to make sure we have some kind of regression test (esp. since the code around this is pretty finicky).

Now, the issue with the test was that is passed whenever any test has been run before (could have even been the same test for which then only the first invocation failed).
Turns out the code around these stack_context functions has little actual functionality and is just made overly complex for what it is -- and, surprise, it's broken.
The ._last_* members are not properly reset in the .pop (& .replace) function:
https://github.com/conda/conda/blob/23.10.0/conda/base/context.py#L1861-L1866 .
Hence, context is not properly reset.

AFAICT, conda.plan is the only consumer of that code.
So, ideally, we can just deprecate and remove that with a short grace period.
Meaning, we don't have to fix it (would actually just be self._stack[self._stack_idx].apply() -> self.apply()) but can just let it be until removal.

@jaimergp
Copy link
Contributor Author

jaimergp commented Nov 25, 2023

So we don't need stack_callback and can just use callback as per conda/conda@c2977d7, right? IOW:

  1. We mark Use callback=reset_context in conda.plan conda#13357 as ready for review and wait for it to be merged.
  2. We revert the patch in tests.yml
  3. We mark this one as ready for review.

@jaimergp jaimergp changed the title debug using stack_context instead of stack_context_default in conda.plan Add tests to ensure that context is properly reset Nov 25, 2023
@mbargull mbargull marked this pull request as ready for review November 26, 2023 12:54
@mbargull
Copy link
Member

So we don't need stack_callback and can just use callback as per conda/conda@c2977d7, right?

Yes, much simpler and working :).

  1. We mark Use callback=reset_context in conda.plan conda#13357 as ready for review and wait for it to be merged.

Done.

  1. We revert the patch in tests.yml

Done, and I squashed my debug commit mess and added a xfail so the tests will succeed for current and (expected fixed) conda>23.10.0 future versions.

  1. We mark this one as ready for review.

Done.

@jaimergp
Copy link
Contributor Author

Hm:

FAILED tests/test_api_build.py::test_add_pip_as_python_dependency_from_condarc_file[False] -
Failed: DID NOT RAISE <class 'subprocess.CalledProcessError'>

@mbargull
Copy link
Member

The canary ones are okay to fail and will pass once the PR for conda is merged.
The 22.11.0 one is odd -- I'm taking a look.

@mbargull
Copy link
Member

Took a look:
For solver=classic we of course need the fixed SubdirData._cache_ mentioned in conda/conda#13357 (comment) .
I'll add the fix to that PR later today or tomorrow morning.

@mbargull
Copy link
Member

The tests should fail again now, but succeed whenever conda/conda#13357 is ready and merged.

mbargull added a commit to jaimergp/conda that referenced this pull request Nov 27, 2023
Dependencies of python are altered acc. to add_pip_as_python_dependency.
In case that configuration value is changed at runtime (currently only
observed in conda-build's tests), SubdirData._cache_ gets invalid.
The offline cache on disk already considers the option, such that the
changes here make runtime behavior consistent with the offline cache.

refs:
- conda#13357 (comment)
- conda/conda-build#5083 (comment)

Signed-off-by: Marcel Bargull <[email protected]>
@jaimergp
Copy link
Contributor Author

Awesome. Thanks @mbargull!

mbargull added a commit to jaimergp/conda that referenced this pull request Nov 27, 2023
Dependencies of python are altered acc. to add_pip_as_python_dependency.
In case that configuration value is changed at runtime (currently only
observed in conda-build's tests), SubdirData._cache_ gets invalid.
The offline cache on disk already considers the option, such that the
changes here make runtime behavior consistent with the offline cache.

refs:
- conda#13357 (comment)
- conda/conda-build#5083 (comment)

Signed-off-by: Marcel Bargull <[email protected]>
@mbargull mbargull marked this pull request as draft November 27, 2023 13:23
mbargull added a commit to mbargull/conda that referenced this pull request Nov 27, 2023
Dependencies of python are altered acc. to add_pip_as_python_dependency.
In case that configuration value is changed at runtime (currently only
observed in conda-build's tests), SubdirData._cache_ gets invalid.
The offline cache on disk already considers the option, such that the
changes here make runtime behavior consistent with the offline cache.

refs:
- conda#13357 (comment)
- conda/conda-build#5083 (comment)

Signed-off-by: Marcel Bargull <[email protected]>
tests/test_api_build.py Outdated Show resolved Hide resolved
@mbargull mbargull marked this pull request as ready for review December 1, 2023 09:18
@jezdez
Copy link
Member

jezdez commented Dec 6, 2023

Is this still worth adding?

@mbargull
Copy link
Member

mbargull commented Dec 6, 2023

Is this still worth adding?

Yes.
If we ever get to the point to remove add_pip_as_python_dependency completely, then we can remove this again.
Until then, I'd rather have more than too few tests for this due to the low-level index injections it causes.

@jezdez jezdez merged commit 06380d7 into conda:main Dec 19, 2023
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed [bot] added once the contributor has signed the CLA
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants