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

[FCL-533] ⚠️ Introduce methods to select the best identifier in various cases #810

Conversation

jacksonj04
Copy link
Collaborator

@jacksonj04 jacksonj04 commented Dec 18, 2024

BREAKING CHANGE

  • Methods which were previously guaranteed to return a Neutral Citation may now return None.

Feat

  • FCL-533: getting scored or preferred identifiers can now be done by type
  • FCL-533: modify human identifier to rely on identifiers framework
  • FCL-533: add scoring to Identifiers

Fix

  • IdentifierSchema: use hasattr instead of getattr with a default when testing required attributes

…when testing required attributes

Using `getattr` with a default of `False` will raise an unexpected error when the attribute is present and has a value of `False`. `hasattr` simply checks for its existence, regardless of value.
This allows us to decide which of a range of possible identifiers should be preferred for a document
This is instead of assuming that an NCN will always be present. As a result, this has had knock-on changes in some other places which were previously relying on this incorrect behaviour. This includes some breaking changes to method signatures, which can now return a `None` in places they previously could not. Since relying on the presence of an NCN is now considered dangerous, these methods have been marked as deprecated.

BREAKING CHANGE: Methods which were previously guaranteed to return a Neutral Citation may now return `None`.
@jacksonj04 jacksonj04 force-pushed the FCL-533-pui-needs-to-be-able-to-select-the-best-identifier-for-any-document branch 2 times, most recently from 7cf2d3c to eabfe34 Compare December 18, 2024 11:18
@jacksonj04 jacksonj04 force-pushed the FCL-533-pui-needs-to-be-able-to-select-the-best-identifier-for-any-document branch from eabfe34 to b204454 Compare December 18, 2024 11:18
Typically, this will be the neutral citation number, should it exist.
Should typically be overridden in subclasses.
"""
def best_human_identifier(self) -> Optional[Identifier]:
Copy link
Collaborator

@dragon-dxw dragon-dxw Dec 18, 2024

Choose a reason for hiding this comment

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

Do all identifiers have a sensible __str__ such that this is a good drop-in replacement despite the type change? (It's probably just the value)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, but I want this to explode where we're not using it properly. This is definitely a breaking change.

@dragon-dxw
Copy link
Collaborator

Could you check whether this causes any typing issues in EUI/PUI?

@jacksonj04
Copy link
Collaborator Author

It definitely does cause typing problems, but they're expected (eg it's places where the apps assume documents always have NCNs). I'm in the process of fixing in EUI (see #1812), and this will be a major version bump.

@dragon-dxw dragon-dxw changed the title [FCL-533] Introduce methods to select the best identifier in various cases [FCL-533] ⚠️ Introduce methods to select the best identifier in various cases Dec 18, 2024
@jacksonj04 jacksonj04 added this pull request to the merge queue Dec 18, 2024
Merged via the queue into main with commit 54332a2 Dec 18, 2024
12 of 14 checks passed
@jacksonj04 jacksonj04 deleted the FCL-533-pui-needs-to-be-able-to-select-the-best-identifier-for-any-document branch December 18, 2024 14:07
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