-
Notifications
You must be signed in to change notification settings - Fork 3k
Upgrade marshmallow from 3.x.x to 4.x.x in azure-ai-ml #41866
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: kshitij-microsoft <166698309+kshitij-microsoft@users.noreply.github.com>
Co-authored-by: kshitij-microsoft <166698309+kshitij-microsoft@users.noreply.github.com>
Co-authored-by: kshitij-microsoft <166698309+kshitij-microsoft@users.noreply.github.com>
Great work! apart from this a test case is failing with the following error: |
Co-authored-by: kshitij-microsoft <166698309+kshitij-microsoft@users.noreply.github.com>
Fixed all pylint issues and test failure in commit 3433418: Pylint fixes:
Test fix:
The upgrade maintains full backward compatibility with marshmallow 3.x while supporting 4.x. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates the azure-ai-ml
package to support Marshmallow 4.x while retaining compatibility with Marshmallow 3.x by adding fallback imports, a custom datetime parser, and updating field parameters.
- Bumped Marshmallow constraint in setup.py to
<5.0.0
- Added fallback import logic and a custom
from_iso_datetime
infields.py
- Replaced
default
withload_default
inindex.py
for thestage
field
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
sdk/ml/azure-ai-ml/setup.py | Updated Marshmallow version constraint to allow <5.0.0 |
sdk/ml/azure-ai-ml/azure/ai/ml/_schema/core/fields.py | Added compatibility imports, custom from_iso_datetime , and updated error messages |
sdk/ml/azure-ai-ml/azure/ai/ml/_schema/assets/index.py | Changed default to load_default for the stage field |
Comments suppressed due to low confidence (2)
sdk/ml/azure-ai-ml/azure/ai/ml/_schema/core/fields.py:64
- Add unit tests that cover the new
from_iso_datetime
function, including parsing ISO8601 strings with 'Z', without timezone, and invalid inputs that should raiseValueError
, to ensure full test coverage of this custom implementation.
def from_iso_datetime(value):
sdk/ml/azure-ai-ml/setup.py:75
- Since new code relies on features introduced in Marshmallow 3.6+, consider updating the lower bound to
>=3.6.0
to avoid runtime errors in environments still using 3.5.x.
"marshmallow>=3.5,<5.0.0",
@@ -14,7 +14,7 @@ | |||
class IndexAssetSchema(ArtifactSchema): | |||
name = fields.Str(required=True, allow_none=False) | |||
id = ArmStr(azureml_type=AzureMLResourceType.INDEX, dump_only=True) | |||
stage = fields.Str(default="Development") | |||
stage = fields.Str(load_default="Development") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The load_default
parameter was introduced in Marshmallow 3.6, but the setup specifies >=3.5
. This will break when using Marshmallow 3.5.x. Consider bumping the minimum version to >=3.6.0
or adding a compatibility fallback for older versions.
stage = fields.Str(load_default="Development") | |
if marshmallow_version >= "3.6.0": | |
stage = fields.Str(load_default="Development") | |
else: | |
stage = fields.Str(missing="Development") |
Copilot uses AI. Check for mistakes.
# Validate that this is a proper datetime string, not just a date | ||
# The original marshmallow from_iso_datetime expects datetime format | ||
if "T" not in value and "Z" not in value and " " not in value: | ||
# This is likely just a date string, not a datetime | ||
raise ValueError(f"Expected datetime string but got date string: {value}") | ||
|
||
# Replace 'Z' with '+00:00' for compatibility with datetime.fromisoformat | ||
if value.endswith("Z"): | ||
value = value[:-1] + "+00:00" | ||
return datetime.fromisoformat(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The manual check for 'T', 'Z', or space may duplicate datetime.fromisoformat
validation. Consider simplifying by relying on fromisoformat
to raise errors for malformed strings or add a comment explaining this pre-check.
# Validate that this is a proper datetime string, not just a date | |
# The original marshmallow from_iso_datetime expects datetime format | |
if "T" not in value and "Z" not in value and " " not in value: | |
# This is likely just a date string, not a datetime | |
raise ValueError(f"Expected datetime string but got date string: {value}") | |
# Replace 'Z' with '+00:00' for compatibility with datetime.fromisoformat | |
if value.endswith("Z"): | |
value = value[:-1] + "+00:00" | |
return datetime.fromisoformat(value) | |
try: | |
# Replace 'Z' with '+00:00' for compatibility with datetime.fromisoformat | |
if value.endswith("Z"): | |
value = value[:-1] + "+00:00" | |
return datetime.fromisoformat(value) | |
except ValueError as e: | |
raise ValueError(f"Invalid datetime string: {value}") from e |
Copilot uses AI. Check for mistakes.
Summary
This PR upgrades the
azure-ai-ml
package to support marshmallow 4.x.x while maintaining backward compatibility with marshmallow 3.x.x. The upgrade addresses all breaking changes introduced in marshmallow 4.0 as outlined in the migration guide.Issues Fixed
This PR resolves the following marshmallow 4.x compatibility errors:
Changes Made
1. Import Updates (
azure/ai/ml/_schema/core/fields.py
)marshmallow.exceptions
instead ofmarshmallow.utils
2. Reference Updates
marshmallow.base.FieldABC
and updated error messages to use generic "marshmallow fields" terminology3. Field Parameter Updates
>=3.5,<4.0.0
to>=3.5,<5.0.0
default="Development"
toload_default="Development"
to use the new marshmallow 4.x parameter name4. Parameter Handling Verification
allowed_values
are properly handled usingkwargs.pop()
patternunknown
parameter usage is compatible with marshmallow 4.xBackward Compatibility
All changes maintain full backward compatibility with marshmallow 3.x.x:
from_iso_datetime
implementation provides the same functionality as the removed utilityTesting
Migration Impact
This upgrade enables:
No breaking changes are introduced for consumers of the azure-ai-ml package.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.