-
Notifications
You must be signed in to change notification settings - Fork 66
refactor(tidy3d): FXC-4436-avoid-ssl-import-for-wasm-build #3059
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: develop
Are you sure you want to change the base?
refactor(tidy3d): FXC-4436-avoid-ssl-import-for-wasm-build #3059
Conversation
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.
Additional Comments (1)
-
tidy3d/web/core/http_util.py, line 203 (link)logic:
create_urllib3_contextexpectsssl_versionto be anssl.TLSVersionenum orNone, not a string. Sinceconfig.web.ssl_versionis now a string (e.g., "TLSv1_2"), this will cause aTypeErrorat runtime when TLS version is configured.You need to convert the string back to
ssl.TLSVersionenum before passing it tocreate_urllib3_context:ssl_version_enum = None if config.web.ssl_version: ssl_version_enum = getattr(ssl.TLSVersion, config.web.ssl_version, None) context = create_urllib3_context(ssl_version=ssl_version_enum)
6 files reviewed, 1 comment
41eec20 to
aa70ca7
Compare
aa70ca7 to
72dcafe
Compare
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.
6 files reviewed, 1 comment
| ssl_version = ( | ||
| ssl.TLSVersion[config.web.ssl_version] if config.web.ssl_version is not None else None | ||
| ) |
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.
style: Potential KeyError if an invalid TLS version string bypasses validation and reaches this point
| ssl_version = ( | |
| ssl.TLSVersion[config.web.ssl_version] if config.web.ssl_version is not None else None | |
| ) | |
| try: | |
| ssl_version = ( | |
| ssl.TLSVersion[config.web.ssl_version] if config.web.ssl_version is not None else None | |
| ) | |
| except KeyError: | |
| log.warning(f"Invalid TLS version '{config.web.ssl_version}', using default") | |
| ssl_version = None |
Prompt To Fix With AI
This is a comment left during a code review.
Path: tidy3d/web/core/http_util.py
Line: 204:206
Comment:
**style:** Potential `KeyError` if an invalid TLS version string bypasses validation and reaches this point
```suggestion
try:
ssl_version = (
ssl.TLSVersion[config.web.ssl_version] if config.web.ssl_version is not None else None
)
except KeyError:
log.warning(f"Invalid TLS version '{config.web.ssl_version}', using default")
ssl_version = None
```
How can I resolve this? If you propose a fix, please make it concise.
Diff CoverageDiff: origin/develop...HEAD, staged and unstaged changes
Summary
tidy3d/web/core/http_util.pyLines 200-211 200
201
202 class TLSAdapter(HTTPAdapter):
203 def init_poolmanager(self, *args: Any, **kwargs: Any) -> None:
! 204 ssl_version = (
205 ssl.TLSVersion[config.web.ssl_version] if config.web.ssl_version is not None else None
206 )
! 207 context = create_urllib3_context(ssl_version=ssl_version)
208 kwargs["ssl_context"] = context
209 return super().init_poolmanager(*args, **kwargs)
210 |
We need to remove the heavy ssl import for the WASM build.
As this is urgent and moving all typing imports behind TYPE_CHECKING is not straightforward with automatic fixes due to pydantic models and the original ssl problem is not solvable by that in general, I decided to only remove this import/type in the config package for now.
Open question: Do we want to extend the except block for all exceptions to catch
ssl.SSLError?Greptile Overview
Greptile Summary
This PR successfully removes the
sslmodule import from the config package (tidy3d/config/) by changing thessl_versionfield fromssl.TLSVersionenum to string-based storage. The implementation includes comprehensive validation that normalizes various TLS version input formats (e.g., "TLS 1.2", "tls1.2", "1.2") into canonical forms (e.g., "TLSv1_2"), and converts back to the enum at the point of use inhttp_util.py.sslimport fromtidy3d/config/legacy.pyandtidy3d/config/sections.pyOptional[ssl.TLSVersion]toOptional[str]throughout config modulesssl.TLSVersionenum objects as input (via.nameattribute)Note: Two other files (
tidy3d/web/cli/app.pyandtidy3d/plugins/dispersion/web.py) still import and catchssl.SSLError, which relates to the PR author's open question about extending exception handling. These files were not modified in this PR and may need future attention for WASM compatibility.Confidence Score: 4/5
Important Files Changed
File Analysis
Sequence Diagram
sequenceDiagram participant User participant WebConfig participant Validator participant HttpUtil participant SSLContext User->>WebConfig: Set ssl_version="TLS 1.2" WebConfig->>Validator: _normalize_ssl_version_name(value) Validator->>Validator: Strip spaces & normalize Validator->>Validator: Regex match TLS version Validator->>Validator: Convert to canonical "TLSv1_2" Validator->>Validator: Validate against TLS_VERSION_CHOICES Validator-->>WebConfig: Return "TLSv1_2" (string) WebConfig-->>User: Store as string User->>HttpUtil: Make HTTPS request HttpUtil->>WebConfig: Get ssl_version (string) WebConfig-->>HttpUtil: "TLSv1_2" HttpUtil->>HttpUtil: Convert ssl.TLSVersion["TLSv1_2"] HttpUtil->>SSLContext: create_urllib3_context(ssl_version=enum) SSLContext-->>HttpUtil: SSL context with TLS 1.2 HttpUtil-->>User: Execute request with SSL context