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

LWPCookieJar.save() gives unexpected results in 3.11.0 #99576

Closed
sebdelsol opened this issue Nov 18, 2022 · 2 comments
Closed

LWPCookieJar.save() gives unexpected results in 3.11.0 #99576

sebdelsol opened this issue Nov 18, 2022 · 2 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@sebdelsol
Copy link

sebdelsol commented Nov 18, 2022

Bug report

LWPCookieJar.save() doesn't truncate the file.
So removing cookies from an existing jar file then saving it gives unexpected results :

from http.cookiejar import LWPCookieJar
from urllib.request import Request, urlopen

lwp = LWPCookieJar("cookies.lwp")

# get some cookies & save
request = Request("https://www.scoopmeacookie.com/give-me-more/")
with urlopen(request) as response:
    lwp.extract_cookies(response, request)
# here's some cookies
print(f"Extracted : {lwp}")
lwp.save()

# clear the jar & save
lwp.clear()
# the jar is now empty
print(f"Clear     : {lwp}")
lwp.save()

# are those cookies really gone ?
lwp.load()
# they're back ! that would be great IRL
# LWPCookieJar.save() didn't truncate the file (os.O_TRUNC is missing)
print(f"Reload    : {lwp}")

Environment

  • Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)]
  • Windows 10 64 bits 22H2

Linked PRs

@sebdelsol sebdelsol added the type-bug An unexpected behavior, bug, or error label Nov 18, 2022
@sebdelsol sebdelsol changed the title LWPCookieJar.save() doesn't truncate the file in 3.11.0 LWPCookieJar.save() gives unexpected results in 3.11.0 Nov 18, 2022
sobolevn added a commit to sobolevn/cpython that referenced this issue Nov 20, 2022
ambv added a commit that referenced this issue Dec 20, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Dec 20, 2022
…asses (pythonGH-99616)

(cherry picked from commit 44892d4)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
ambv added a commit that referenced this issue Dec 20, 2022
…lasses (GH-99616) (GH-100377)

(cherry picked from commit 44892d4)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
@ambv
Copy link
Contributor

ambv commented Dec 20, 2022

Fixed for release in 3.11.2 and 3.12.0.

@ambv ambv closed this as completed Dec 20, 2022
@ambv
Copy link
Contributor

ambv commented Dec 20, 2022

Thanks for the fix, @sobolevn! 🍰

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

No branches or pull requests

2 participants