GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Query Tool: first 4 MB of a large file is loaded twice when a later chunk isn't valid UTF-8 · Issue #10462 · pgadmin-org/pgadmin4

Query Tool: first 4 MB of a large file is loaded twice when a later chunk isn't valid UTF-8 #10462

New issue
Copy link
New issue
Copy link
Closed
Closed
Query Tool: first 4 MB of a large file is loaded twice when a later chunk isn't valid UTF-8#10462
Copy link

Description

@Barry-Lenhart
Barry-Lenhart
opened on Sep 28, 2026
Issue body actions

Describe the bug

When a file larger than 4 MB is opened in the Query Tool, and a byte that isn't valid UTF-8 appears after the first 4 MB (for example, a Latin-1 é in an otherwise UTF-8 SQL dump), the file's first 4 MB are sent to the editor twice.

load_file streams read_file_generator(file_path, enc). enc comes from check_file_for_bom_and_binary(), which only looks at the first 1024 bytes, so it is utf-8 for such a file. read_file_generator() then reads the file in 4 MB chunks and yields each chunk as it goes. When a later chunk raises UnicodeDecodeError, the except branch reopens the file with latin-1 and yields it again from the start, after the earlier chunks have already been sent. If the user then saves the file, the duplicated content is written back.

To Reproduce

  1. Create a file of just over 5 MB that is UTF-8 except for one Latin-1 byte near the end:
    data = b"SELECT 1;\r\n" * (5 * 1024 * 1024 // 11) + b"-- caf\xe9\r\n"
    open("big.sql", "wb").write(data)
  2. Read it the way load_file does:
    from pgadmin.misc.file_manager import read_file_generator
    out = "".join(read_file_generator("big.sql", "utf-8"))
    print(len(data), len(out))  # 5242884 9437188
    The output is 9,437,188 characters for a 5,242,884-byte file: the first 4 MB appear twice.

I checked this by calling the function on current master; I haven't gone through the UI with a file this size.

Expected behavior

The file's content appears exactly once, decoded as Latin-1 when it isn't valid in the detected encoding, which is what the fallback is meant to do.

Desktop

  • pgAdmin version: current master
  • Mode: any (the file is read on the server)

Additional context

The same function uses codecs.open(), which is deprecated as of Python 3.14.

Would you like me to open a PR that fixes both? It would check which encoding applies before yielding anything, then read the file with the built-in open() (with newline='', so line endings stay exactly as they are).

Activity

  1. dev-hari-prasad commented on Oct 7, 2026

    @dev-hari-prasad
    dev-hari-prasad
    on Oct 7, 2026
    Contributor
    More actions

    Thanks, @Barry-Lenhart, for reporting this issue.

    Although I would have wished for you to work on this PR, I only happened to see your 'Would you like me to open PR' sentence after I wrote a PR. Sorry about that if you were trying to contribute, feel free to contribute PRs and ways.

    Thanks again!

  2. dev-hari-prasad
    added a commit that references this issue on Oct 7, 2026

    Fix Query Tool duplicate file chunk loading on non-UTF-8 fallback

    This issue will close once commit 1a11399 is merged into the 'master' branch.
    1a11399
  3. dpage
    added a commit that references this issue on Oct 12, 2026

    Fix duplicated content when opening large non-UTF-8 files in the Quer…

    aaa0c8f
  4. dpage commented on Oct 12, 2026

    @dpage
    dpage
    on Oct 12, 2026
    Contributor
    More actions

    Fixed by aaa0c8f (#10508).

  5. dpage
    closed this as completedon Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.