Skip to content

fix: handle missing clipboard in headless environments for langflow api-key command#12351

Open
andifilhohub wants to merge 2 commits intorelease-1.9.0from
fix/api-key-pyperclip-headless
Open

fix: handle missing clipboard in headless environments for langflow api-key command#12351
andifilhohub wants to merge 2 commits intorelease-1.9.0from
fix/api-key-pyperclip-headless

Conversation

@andifilhohub
Copy link
Copy Markdown
Member

Summary

  • langflow api-key crashed with PyperclipException in headless environments (Docker, SSH) because pyperclip.copy() was called without error handling, before any output was shown
  • The crash occurred after the key was generated and the previous one deleted from the database — making the new key unrecoverable, since it only exists in plain text at creation time
  • The fix wraps pyperclip.copy() in a try/except: the API key is always displayed in the terminal regardless of clipboard availability

Changes

  • api_key_banner: wraps pyperclip.copy() in try/except; adapts banner text based on whether clipboard is available or not
  • Added 5 unit tests covering: clipboard available, headless without clipboard, UnicodeEncodeError fallback with and without clipboard

Test plan

  • python -m pytest src/backend/tests/unit/test_cli.py::TestApiKeyBanner -v
  • Manually validate in a Docker container: langflow api-key should display the key without raising an exception

…pi-key command

pyperclip.copy() was called without error handling, causing an unhandled
PyperclipException in Docker/SSH environments where no clipboard mechanism
is available. The crash happened after the key was generated and the previous
one deleted, making the new key unrecoverable.

- Wrap pyperclip.copy() in try/except; show key regardless of clipboard availability
- Adapt banner hint text based on whether clipboard copy succeeded
- Add unit tests covering headless fallback and UnicodeEncodeError scenarios
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 26, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 84ca39c2-8fb9-4ec3-98df-49fad87d94e2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/api-key-pyperclip-headless

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added the bug Something isn't working label Mar 26, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Mar 26, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 26, 2026

Codecov Report

❌ Patch coverage is 0% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.26%. Comparing base (41d34b2) to head (64d8863).

Files with missing lines Patch % Lines
src/backend/base/langflow/__main__.py 0.00% 10 Missing ⚠️

❌ Your project check has failed because the head coverage (44.71%) is below the target coverage (60.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                @@
##           release-1.9.0   #12351      +/-   ##
=================================================
- Coverage          48.23%   46.26%   -1.97%     
=================================================
  Files               1848     1847       -1     
  Lines             160885   161555     +670     
  Branches           23643    23721      +78     
=================================================
- Hits               77607    74751    -2856     
- Misses             82394    85920    +3526     
  Partials             884      884              
Flag Coverage Δ
backend 43.08% <0.00%> (-11.80%) ⬇️
frontend 47.29% <ø> (-0.30%) ⬇️
lfx 44.71% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/backend/base/langflow/__main__.py 19.71% <0.00%> (-35.59%) ⬇️

... and 337 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 26, 2026

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 26%
26.68% (27018/101229) 63.32% (3345/5282) 28.82% (639/2217)

Unit Test Results

Tests Skipped Failures Errors Time
2784 0 💤 0 ❌ 0 🔥 4m 1s ⏱️

@andifilhohub andifilhohub force-pushed the fix/api-key-pyperclip-headless branch from 6a0e4c3 to 64d8863 Compare March 26, 2026 19:35
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant