René's URL Explorer Experiment


Title: lazyproperty re-evaluates its getter on every access when the cached value is None · Issue #1600 · python-openxml/python-docx · GitHub

Open Graph Title: lazyproperty re-evaluates its getter on every access when the cached value is None · Issue #1600 · python-openxml/python-docx

X Title: lazyproperty re-evaluates its getter on every access when the cached value is None · Issue #1600 · python-openxml/python-docx

Description: Summary docx.shared.lazyproperty (src/docx/shared.py) does not correctly cache a wrapped getter whose correct return value is None. Instead of evaluating the getter once and reusing the cached value, it re-invokes the getter on every acc...

Open Graph Description: Summary docx.shared.lazyproperty (src/docx/shared.py) does not correctly cache a wrapped getter whose correct return value is None. Instead of evaluating the getter once and reusing the cached valu...

X Description: Summary docx.shared.lazyproperty (src/docx/shared.py) does not correctly cache a wrapped getter whose correct return value is None. Instead of evaluating the getter once and reusing the cached valu...

Opengraph URL: https://github.com/python-openxml/python-docx/issues/1600

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"lazyproperty re-evaluates its getter on every access when the cached value is None","articleBody":"## Summary\n\n`docx.shared.lazyproperty` (`src/docx/shared.py`) does not correctly cache a wrapped getter whose correct return value is `None`. Instead of evaluating the getter once and reusing the cached value, it re-invokes the getter on **every** access whenever the cached value happens to be `None`.\n\n## Mechanism\n\n`lazyproperty.__get__` uses presence-in-`__dict__`-via-`None`-sentinel to decide whether the value has already been computed:\n\n```python\ndef __get__(self, obj, type=None):\n    ...\n    value = obj.__dict__.get(self._name)\n    if value is None:\n        value = self._fget(obj)\n        obj.__dict__[self._name] = value\n    return cast(T, value)\n```\n\n`dict.get(key)` returns `None` both when the key is absent *and* when the key is present with value `None`. Since `None` is a completely valid thing for a getter to legitimately compute (e.g. \"look up this optional related object; there isn't one yet\"), the two cases are indistinguishable here. Every subsequent access re-runs `fget` and re-stores `None`, forever.\n\nThis directly contradicts the class's own docstring, which states:\n\n> \"...evaluated only on first access; the resulting value is cached and that same value returned on second and later access **without re-evaluation** of the method.\"\n\nand\n\n> \"One common use is to construct collaborator objects, removing that 'real work' from the constructor, while still only executing once.\"\n\nIf such a getter has any side effect (e.g. constructs and registers an object, appends to a log, does I/O), that side effect fires on every access instead of once, breaking the documented idempotence guarantee.\n\n## Reproduction (verified against PyPI `python-docx` 1.2.0 and current `master`)\n\n```python\nfrom docx.shared import lazyproperty\n\nclass Widget:\n    def __init__(self):\n        self.call_count = 0\n\n    @lazyproperty\n    def maybe_missing_child(self):\n        self.call_count += 1\n        return None\n\nw = Widget()\n_ = w.maybe_missing_child\n_ = w.maybe_missing_child\n_ = w.maybe_missing_child\nprint(w.call_count)   # prints 3\n```\n\nOutput:\n```\nresults: None, None, None\nfget call_count: 3 (lazyproperty's own docstring promises this must be 1)\n```\n\n## Expected vs actual\n\n- Expected: `fget` runs exactly once; the cached `None` is returned on subsequent accesses (matching the documented \"evaluated only on first access\" / \"without re-evaluation\" contract).\n- Actual: `fget` runs again on every access for as long as it keeps returning `None`.\n\n## Suggested fix\n\nUse a proper \"not yet computed\" sentinel instead of relying on `None`, e.g.:\n\n```python\n_NOT_COMPUTED = object()\n\ndef __get__(self, obj, type=None):\n    if obj is None:\n        return self\n    value = obj.__dict__.get(self._name, _NOT_COMPUTED)\n    if value is _NOT_COMPUTED:\n        value = self._fget(obj)\n        obj.__dict__[self._name] = value\n    return cast(T, value)\n```\n\nor check `self._name in obj.__dict__` instead of comparing the fetched value to `None`.\n\n## Notes\n\n- I did not find any current `@lazyproperty`-decorated method inside python-docx's own element classes that happens to return `None` today, so this doesn't currently misbehave through the document-editing API itself. However, `lazyproperty` is a general-purpose, documented utility in `docx.shared` that the project's own docstring explicitly recommends for exactly this \"may return an absent/optional collaborator\" use case, and it's the standard tool used throughout `python-docx`'s own oxml element classes (see e.g. `docx/oxml/xmlchemy.py`, `docx/oxml/text/pagebreak.py`) as well as by third-party code extending python-docx with custom oxml element classes (a common, documented customization pattern) - so a future or third-party getter that legitimately returns `None` will silently lose its caching and idempotence guarantees.\n- Verified this reproduces identically against the current `master` branch (fetched fresh via the GitHub raw URL) - the `__get__` implementation is unchanged there.\n","author":{"url":"https://github.com/VANDRANKI","@type":"Person","name":"VANDRANKI"},"datePublished":"2026-08-25T19:36:47Z","url":"https://github.com/python-openxml/python-docx/issues/1600"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:df856bb1-292e-9df3-db7b-3f87fd06f1c8
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC3F2:30DBED:7B7562:8CDD8B:6AFF6389
html-safe-noncea0f3c379ff52f183f7f47c00837cd0d02a9d3a9119d19f5dd62e5a98bc2cfaec
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDM0YyOjMwREJFRDo3Qjc1NjI6OENERDhCOjZBRkY2Mzg5IiwidmlzaXRvcl9pZCI6IjY3NzMzNDMwMTMwNTQ2Njk3MDUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmace3821445b6b1ae8eeaae985721fd4b4b160ee09e6381d98ec7607971ceb08160
hovercard-subject-tagissue:5249835671
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-openxml/python-docx/1600/issue_layout
twitter:imagehttps://opengraph.githubassets.com/c569198acfd76b3e5d9f52271868fc17c0ed5d315089104255081d90207c7c69/python-openxml/python-docx/issues/1600
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/c569198acfd76b3e5d9f52271868fc17c0ed5d315089104255081d90207c7c69/python-openxml/python-docx/issues/1600
og:image:altSummary docx.shared.lazyproperty (src/docx/shared.py) does not correctly cache a wrapped getter whose correct return value is None. Instead of evaluating the getter once and reusing the cached valu...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameVANDRANKI
hostnamegithub.com
expected-hostnamegithub.com
None41b58589a1c4eda1e3c8904144a412b88ca4455f63ca2ad3629f2e9f3c3a1d12
turbo-cache-controlno-preview
go-importgithub.com/python-openxml/python-docx git https://github.com/python-openxml/python-docx.git
octolytics-dimension-user_id3403760
octolytics-dimension-user_loginpython-openxml
octolytics-dimension-repository_id13592924
octolytics-dimension-repository_nwopython-openxml/python-docx
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id13592924
octolytics-dimension-repository_network_root_nwopython-openxml/python-docx
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8968d6d6acc65d74e4df332d23932dd3fd0502a4
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python-openxml/python-docx/issues/1600#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-openxml%2Fpython-docx%2Fissues%2F1600
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-openxml%2Fpython-docx%2Fissues%2F1600
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python-openxml%2Fpython-docx
Reloadhttps://github.com/python-openxml/python-docx/issues/1600
Reloadhttps://github.com/python-openxml/python-docx/issues/1600
Reloadhttps://github.com/python-openxml/python-docx/issues/1600
python-openxmlhttps://github.com/python-openxml
python-docxhttps://github.com/python-openxml/python-docx
Codehttps://github.com/python-openxml/python-docx
Issues387 (387)https://github.com/python-openxml/python-docx/issues
Pull requests167 (167)https://github.com/python-openxml/python-docx/pulls
Actionshttps://github.com/python-openxml/python-docx/actions
Projectshttps://github.com/python-openxml/python-docx/projects
Wikihttps://github.com/python-openxml/python-docx/wiki
Security and qualityhttps://github.com/python-openxml/python-docx/security
Insightshttps://github.com/python-openxml/python-docx/insights
https://github.com/python-openxml/python-docx
New issuehttps://github.com/login?return_to=https://github.com/python-openxml/python-docx/issues/1600
New issuehttps://github.com/login?return_to=https://github.com/python-openxml/python-docx/issues/1600
#1626https://github.com/python-openxml/python-docx/pull/1626
lazyproperty re-evaluates its getter on every access when the cached value is Nonehttps://github.com/python-openxml/python-docx/issues/1600#top
#1626https://github.com/python-openxml/python-docx/pull/1626
https://github.com/VANDRANKI
VANDRANKIhttps://github.com/VANDRANKI
on Aug 25, 2026https://github.com/python-openxml/python-docx/issues/1600#issue-5249835671
Sign up for freehttps://github.com/signup?return_to=https://github.com/python-openxml/python-docx/issues/1600
Sign in to commenthttps://github.com/login?return_to=https://github.com/python-openxml/python-docx/issues/1600
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.