Open
Conversation
d00e8dd to
5a49127
Compare
1acd354 to
2f001fe
Compare
The .dict() method is deprecated in Pydantic V2 (PydanticDeprecatedSince20) and slated for removal in V3. The identically-behaving replacement is .model_dump() — all existing keyword arguments (exclude_unset, exclude, by_alias) are supported unchanged. Galaxy has already completed the bulk of the Pydantic v2 migration; these are the straggling call sites still emitting deprecation warnings in CI.
.json() is deprecated in Pydantic V2; .model_dump_json() is the identically-behaving replacement.
Pydantic V2 deprecates Model.parse_obj() (use Model.model_validate()) and the top-level parse_obj_as() helper (use TypeAdapter(T).validate_python()).
Pydantic V2 deprecates Model.__fields__ in favour of the Model.model_fields class property.
ShareableService._get_sharing_status was handing SharingStatus a
list of raw {'id': ..., 'email': ...} dicts for the
users_shared_with field, which is declared as list[UserEmail].
Pydantic model construction does not coerce the list in this code
path, so at serialization time the field holds dicts and Pydantic
emits PydanticSerializationUnexpectedValue warnings.
Build UserEmail instances directly — the EncodedDatabaseIdField
BeforeValidator handles id encoding.
The ToolDataField schema declares base_dir: List[str], but TabularToolDataField.to_dict was producing a single-element tuple, which trips PydanticSerializationUnexpectedValue for tuple-vs-list mismatch on /api/tool_data responses.
Dictifiable.to_dict() stringifies any datetime attribute via isoformat() before returning. UserModel.last_password_change is declared as Optional[datetime], so model_construct() stashes the string as-is and Pydantic emits PydanticSerializationUnexpectedValue on whoami responses. Add a no-op value_mapper entry to preserve the datetime object through to_dict, so model_construct sees the correct type.
FastAPIExports._parse_export_metadata was passing the raw payload dict straight into ExportObjectRequestMetadata.model_construct(payload=...). The field is declared as Union[WriteStoreToPayload, ShortTermStoreExportPayload], so the stashed dict triggers PydanticSerializationUnexpectedValue on any /api/exports call that surfaces historical export metadata. Mirror the discrimination logic already in HistoryExportsManager.get_record_metadata: pick WriteStoreToPayload when target_uri is present, otherwise ShortTermStoreExportPayload.
RefactorResponse.workflow uses WrapSerializer(safe_wraps) to wrap
the inner dict serialization in a fallback that calls
safe_dumps() on failure. The helper was annotated '-> str', but
the happy path (nxt(v) on a dict field) returns a nested dict
— not a string — so Pydantic emits
PydanticSerializationUnexpectedValue on /api/workflows/{id}/refactor
responses, expecting str and receiving dict.
The actual return type is Union[str, Any] (Any from nxt's inner
serialization). Annotate the helper as -> Any so Pydantic stops
enforcing a str output type on the happy path.
managers/datasets.py, managers/folders.py, and managers/libraries.py each carried an identical inner closure (named make_tuples) that returned a list of 2-element Python tuples. The corresponding response schemas (DatasetAssociationRoles, LibraryCurrentPermissions, LibraryFolderCurrentPermissions) declare those fields as list[RoleNameIdTuple] where RoleNameIdTuple = list[str], so every call emitted PydanticSerializationUnexpectedValue at serialization time — the field stored tuples but the type alias is list[str]. Extract a single role_name_id_pairs(roles, private_role_emails, encode_id) helper in galaxy.model.db.role, where its companion get_private_role_user_emails_dict already lives. The helper is pure data shaping: it builds [displayed_name, encoded_id] inner *lists* (not tuples) so the shape matches the schema alias, and keeps the private-role -> user email rendering consistent across the three call sites. No behaviour change on the wire: RoleNameIdTuple is still serialized as a 2-element JSON array.
Prevent regressions by turning PydanticDeprecatedSince20 warnings into errors, now that all V1-style API usage has been replaced.
gravity still uses class-based Config which triggers PydanticDeprecatedSince20; ignore it for that module only.
TPV still uses class-based Config which triggers PydanticDeprecatedSince20; ignore it for that module only.
2f001fe to
bd74100
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
These are straightforward refactors to use non-deprecated methods
How to test the changes?
(Select all options that apply)
License