Skip to content

Potential issue with Ltree.lca() handling of prefix paths #766

@coryking

Description

@coryking

While testing an isolated copy of the Ltree implementation, an AI assistant (Claude-Sonnet via Cursor) identified what might be unexpected behavior in the lca() method when one path is a prefix of another.

Example:

ltree = Ltree('1.2.3.4.5')
result = ltree.lca('1.2.3', '1.2.3.4')
print(result) # Returns Ltree('1.2') but expected Ltree('1.2.3')

The current implementation appears to stop at '1.2' because it hits the condition:

len(other) <= index + 1

when processing the shorter path '1.2.3'.

However, since '1.2.3' is a valid prefix shared by all paths in the example, it seems this should be the LCA.

Important Note: This behavior was identified through unit testing, but I haven't verified if this aligns with or differs from PostgreSQL's native ltree implementation. If this behavior is intentionally matching PostgreSQL's ltree module, please disregard this report.

Would appreciate confirmation whether this is:

  1. Expected behavior matching PostgreSQL
  2. A legitimate issue
  3. Working as intended for other reasons

Thank you for maintaining this useful library!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions