Skip to content

5.0.2.post2: restore methods lxml 5.0 removed; static link fix; postN version - #3

Merged
icanhasmath merged 4 commits into
5.0.2.xfrom
5.0.2.post2
Nov 20, 2026
Merged

icanhasmath merged 4 commits into
5.0.2.xfrom
5.0.2.post2

Conversation

@icanhasmath

Copy link
Copy Markdown

lxml 5.0.2.post2, on top of 5.0.2+security.1 (tag 5.0.2.1). New base branch 5.0.2.x = 4009508 (the 5.0.2.1 release commit).

Why

A customer moving a Python 2.7 runtime from lxml 4.9 to our 5.0.2.1 hit AttributeError: 'lxml.etree.ETXPath' object has no attribute 'evaluate'. Upstream lxml 5.0 removed three methods that had been deprecated since 2.0: XPath.evaluate(), parser.setElementClassLookup() and XSLT.apply(). These are Py2-era runtimes that won't move to newer lxml, so the fork keeps them.

Commits

  1. Restore deprecated methods that lxml 5.0 removed. The code is verbatim from lxml 4.9.2 (xpath.pxi, parser.pxi, xslt.pxi), and each method is a thin alias of the supported call. New test module: tests/test_deprecated_aliases.py.
  2. Link the libraries xml2-config and xslt-config report. This is the setupinfo.py fix the Platform has carried as inventory patch d4d217d2 on 5.0.2.1. Static libxml2.a needs -liconv, and without it etree.so fails to import. With the fix in the source, 5.0.2.post2 needs no inventory patch.
  3. Parse a .postN suffix in LXML_VERSION. Without this, 5.0.2.post2 would unpack to (5, 0, 2, 'post2'), which breaks tuple comparisons on Python 3. It now gives (5, 0, 2, 2). This also fixes upstream's test_etree.test_version, which fails on 5.0.2.1 because LXML_VERSION is (5, 0, '2+security', 1).
  4. Release 5.0.2.post2: __version__ and CHANGES.txt.

Testing

Built in place on Python 2.7.18 with Cython 3.0.11, libxml2 2.15.3 and libxslt 1.1.45:

  • test_deprecated_aliases: 7/7 pass.
  • A smoke test of the customer's reproduction plus each restored method fails 5/5 on 5.0.2.1 and passes 5/5 here.
  • Full test.py: the failure set is the same as on 5.0.2.1, minus test_version, which now passes. The remaining 21 failures and 20 errors are host artifacts (libxml2 2.15 against tests written for 2.12, plus network tests) and fail identically on both.

After merge: tag 5.0.2.2, create a GitHub release, import into the inventory as lxml 5.0.2.2 (copy of 5.0.2.1 without patch d4d217d2), then run Platform builds and QA.

icanhasmath and others added 4 commits November 19, 2026 15:53
lxml 5.0 removed XPath.evaluate() (XPath, ETXPath, XPathEvaluator),
parser.setElementClassLookup() and XSLT.apply(), all deprecated since
lxml 2.0.  Code written against lxml 4.x that still calls them fails with
AttributeError after an upgrade to 5.0.  Bring them back verbatim from
lxml 4.9.2: each is a thin alias of the supported call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lxml links a fixed list (xslt exslt xml2 rt z m) and takes only the -L
directories from xml2-config/xslt-config --libs.  Against static libxml2.a
and libxslt.a, which carry no DT_NEEDED entries, that drops libxml2's own
dependencies: with GNU libiconv, etree.so and objectify.so are left with
undefined libiconv/libiconv_open/libiconv_close and fail on import.

Append every -l the config tools report that is not already listed.  With
shared libraries this is harmless.  The ActiveState Platform has carried
this as an inventory patch on 5.0.2.1; it now lives in the source.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
__unpackDottedVersion() left an unknown suffix as a string, so a post
release would give LXML_VERSION = (5, 0, 2, 'post2'), which raises
TypeError when compared with an all-integer tuple on Python 3.  Read
postN as the number N: 5.0.2.post2 -> (5, 0, 2, 2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Version string: 5.0.2.post2
Git tag: 5.0.2.2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@icanhasmath
icanhasmath marked this pull request as ready for review November 20, 2026 06:40

@ezequielp-activestate ezequielp-activestate left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve: 0 blockers.

🔴 Blockers: None

📋 Checked

  • The restored methods are an exact revert of the upstream removal. Upstream removed exactly these three methods in lxml commit 59ccc8c ("Remove redundant and long deprecated methods"), and the 5.0.0 changelog lists no others. XPath.evaluate(), setElementClassLookup() and XSLT.apply() here match lxml-4.9.2 line for line.
  • Built and tested in place on Python 2.7.18 (python:2.7 image, Cython 3.0.11, libxml2 2.9.4, libxslt 1.1.32), with AS_DEPENDENCIES_DIR=/:
    • Base 5.0.2.1 with the new test file copied in: test.py ran 1974 tests with 2 failures and 6 errors. The 8 are the 7 new tests plus test_etree.test_version.
    • This PR: the same 1974 tests all pass.
    • The customer's ETXPath(...).evaluate() raises AttributeError on the base and works here.
  • LXML_VERSION is (5, 0, u'2+security', 1) on the base and (5, 0, 2, 2) here.
  • The package version is right: setup.py --version and versioninfo.version() both give 5.0.2.post2.
  • The link fix works when setup finds libxml2 through xml2-config. I pointed it at a stub xml2-config that reports -lxml2 -liconv -lz -lm. Base libraries() gives [xslt, exslt, xml2, rt, z, m], and the PR gives the same list plus iconv.

🟡 The link fix does nothing when setup finds libxml2 through pkg-config. get_library_versions() (setupinfo.py:507) tries pkg-config before xml2-config, and pkg-config --libs leaves out Libs.private: on Debian, pkg-config --libs libxml-2.0 prints only -lxml2, while --static --libs also gives -licu… -lz -llzma -lm. On that path libraries() is unchanged; I ran it on both trees and got identical lists. It's fine as long as the Platform builder has no pkg-config that finds our libxml2, and since patch d4d217d2 worked on 5.0.2.1, it probably doesn't. Before dropping the patch from the 5.0.2.2 import, check that the first Platform build log has -liconv on the etree.so link line.

⚪ For the customer: their move from 4.9 to 5.0 also changes the default to resolve_entities='internal', so external entities (XXE) are no longer expanded (5.0.0 changelog, LP#1742885). That change is intended and this PR rightly leaves it alone, but it's the next difference they may run into.

⚠️ Not assessed

  • I didn't compare the code against inventory patch d4d217d2.
  • I didn't do a real static link against libxml2.a with GNU libiconv.
  • I didn't run Python 3 or Windows builds.

@icanhasmath

Copy link
Copy Markdown
Author

Thanks for the thorough review.

🟡 pkg-config path. I checked this on the Platform builder. The current Forsta x86 build (commit c92e1eb0) builds lxml 5.0.2.1 with inventory patch d4d217d2, which is the same setupinfo.py change as commit 2 here. Its etree.so link line is:

... etree.o -L/var/builds/deps/1/installdir/usr/lib ... -lxslt -lexslt -lxml2 -lrt -lz -lm -lpthread -liconv -ldl -o .../etree.so

So on the builder, the libraries a static libxml2 needs (-lpthread -liconv -ldl) do reach the link, whichever discovery path setup takes. I'm leaving the code as it is, because adding --static on the pkg-config path would also add Libs.private to shared builds, as new NEEDED entries. As you suggested, the first 5.0.2.2 Platform build is still a gate: its etree.so link line must have -liconv, and etree/objectify must import, before the release ships.

⚪ XXE default. Agreed. The resolve_entities='internal' default arrived with the 4.9 → 5.0 move (and in our fork with the CVE-2026-41066 backport in 5.0.2.1). I'll call it out to the customer alongside the evaluate() fix as an intended behavior change.

@icanhasmath
icanhasmath merged commit b7e0068 into 5.0.2.x Nov 20, 2026
0 of 110 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants