Skip to content

venv bug: Function “_old_fish_prompt” does not exist when activating venv in child process #93858

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

Closed
thomasbbrunner opened this issue Jun 15, 2022 · 6 comments · Fixed by #93931
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@thomasbbrunner
Copy link
Contributor

thomasbbrunner commented Jun 15, 2022

Bug report

Looked for similar issues and could not find any.

Steps to reproduce bug:

  1. activate venv
  2. spawn child fish process (or start tmux session)
  3. activate same venv
source activate.fish
fish
source activate.fish

Should output:
functions: Function “_old_fish_prompt” does not exist

Cause

I think I've identified the reason for the bug:

  1. The environment variables set in activate.fish are exported to child processes (script uses set -gx to set the variables).
  2. However, the function _old_fish_prompt is not exported to child processes.

So, when we run fish from another fish session (such as in tmux), the variables set in activate.fish are present in the child process, but the functions are not.

Fix

I've written a fix for this, which is to test if the _old_fish_prompt function exists before attempting to delete it. I can make a PR with this fix.

Also, the implementation from virtualenv does not suffer from this bug. They check if the function exists before deleting it.

Your environment

Ubuntu 22.04 amd64
Python 3.10.4
Python and venv packages installed from apt

@thomasbbrunner thomasbbrunner added the type-bug An unexpected behavior, bug, or error label Jun 15, 2022
@AlexWaygood AlexWaygood added the stdlib Python modules in the Lib dir label Jun 15, 2022
@vsajip
Copy link
Member

vsajip commented Jun 15, 2022

I can make a PR with this fix.

Please do, and thanks for the report.

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 18, 2022
…tances (pythonGH-93931)

(cherry picked from commit 1172172)

Co-authored-by: Thomas B. Brunner <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 18, 2022
…tances (pythonGH-93931)

(cherry picked from commit 1172172)

Co-authored-by: Thomas B. Brunner <[email protected]>
vsajip pushed a commit that referenced this issue Oct 18, 2022
vsajip pushed a commit that referenced this issue Oct 18, 2022
@banteg
Copy link

banteg commented Apr 1, 2024

still seeing this in 2024 on deactivate. just a normal shell, not tmux or nested or anything.

fish: Unknown command: _old_fish_prompt
fish:
_old_fish_prompt
^~~~~~~~~~~~~~~^
in command substitution
in function '_warp_prompt'
	called on line 1 of file /var/folders/zq/vyffd7255m38x2mbmvvd102w0000gn/T/.tmpP4yVid
in command substitution
	called on line 120 of file /var/folders/zq/vyffd7255m38x2mbmvvd102w0000gn/T/.tmpP4yVid
in function 'warp_precmd'
in event handler: handler for generic event 'fish_prompt'
fish: Unknown command
        set -l prompt (_old_fish_prompt)
                      ^~~~~~~~~~~~~~~~~^
in function '_warp_prompt'
	called on line 1 of file /var/folders/zq/vyffd7255m38x2mbmvvd102w0000gn/T/.tmpP4yVid
in command substitution
	called on line 120 of file /var/folders/zq/vyffd7255m38x2mbmvvd102w0000gn/T/.tmpP4yVid
in function 'warp_precmd'
in event handler: handler for generic event 'fish_prompt'

@thomasbbrunner
Copy link
Contributor Author

thomasbbrunner commented Apr 9, 2024

@banteg Which Python version are you using? Which system?

Also, are you using venv or virtualenv to create your environment?

@banteg
Copy link

banteg commented Apr 9, 2024

can't replicate anymore, sorry for bothering

@wonjoonSeol-WS
Copy link

wonjoonSeol-WS commented May 8, 2024

I am also getting the same error message when using deactivate:

image
which python3
/opt/homebrew/bin/python3
Python 3.12.3

I used poetry env use command to create the environment.

fish -version
fish, version 3.7.1

mac OS.

Update: The issue seem to do with Warp terminal. Running the same commands on different terminal has no issue.

@Obsessivex
Copy link

I've have similar problem and my workaround is, deactivate > fish > source "desired/venv".
This is work around, not solution.
Would love to hear solution if there is any

⋊> ~/c/webscrape on dev ⨯ source /Users/burak/code/webscrape/webscrap
evenv/bin/activate.fish
functions: Function '_old_fish_prompt' does not exist

~/code/webscrape/webscrapevenv/bin/activate.fish (line 18): 
        functions -c _old_fish_prompt fish_prompt
        ^
in function 'deactivate' with arguments 'nondestructive'
        called on line 30 of file ~/code/webscrape/webscrapevenv/bin/activate.fish
from sourcing file ~/code/webscrape/webscrapevenv/bin/activate.fish

(Type 'help functions' for related documentation)
functions: Function 'fish_prompt' does not exist

~/code/webscrape/webscrapevenv/bin/activate.fish (line 47): 
    functions -c fish_prompt _old_fish_prompt
    ^
from sourcing file ~/code/webscrape/webscrapevenv/bin/activate.fish

(Type 'help functions' for related documentation)
fish: Unknown command: _old_fish_prompt
~/code/webscrape/webscrapevenv/bin/activate.fish (line 71): 
        _old_fish_prompt
        ^~~~~~~~~~~~~~~^
in function 'fish_prompt'
in command substitution
(webscrapevenv) deactivate                            (base) 23:02:44
functions: Function '_old_fish_prompt' does not exist

~/code/webscrape/webscrapevenv/bin/activate.fish (line 18): 
        functions -c _old_fish_prompt fish_prompt
        ^
in function 'deactivate'

(Type 'help functions' for related documentation)
[email protected] /Users/burak/code/webscrape > fish
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
⋊> ~/c/webscrape on dev ⨯ source /Users/burak/code/webscrape/webscrap
evenv/bin/activate.fish

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants