Skip to content

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

Closed

Description

@thomasbbrunner

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

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Jun 15, 2022
  2. vsajip commented on Jun 15, 2022

    @vsajip
    Member

    I can make a PR with this fix.

    Please do, and thanks for the report.

  3. added a commit that references this issue on Jun 27, 2022
  4. added 2 commits that reference this issue on Oct 18, 2022
  5. added 2 commits that reference this issue on Oct 18, 2022
  6. banteg commented on Apr 1, 2024

    @banteg

    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'
    
  7. thomasbbrunner commented on Apr 9, 2024

    @thomasbbrunner
    ContributorAuthor

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

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

  8. banteg commented on Apr 9, 2024

    @banteg

    can't replicate anymore, sorry for bothering

  9. wonjoonSeol commented on May 8, 2024

    @wonjoonSeol

    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.

  10. Obsessivex commented on Jun 11, 2024

    @Obsessivex

    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)
    burak@Buraks-MacBook-Pro.local /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

Metadata

Metadata

Assignees

Labels

stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions