Repository navigation
fix: portal setting #7796
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
Merged
Merged
fix: portal setting #7796
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Oops, something went wrong.
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.
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.
Here is the code review focusing on irregularities, potential issues, and optimization suggestions:
1. Potential Logic Issue:
setattrfor File Fields inauth_configMergeIssue: The merging logic for
auth_configuses{**(portal.auth_config or {}), **value}. Ifportal.auth_configcontains keys that are file paths or objects (e.g., ifauth_configstores file references), a shallow merge dictionary update might not deep-merge nested structures correctly. However, this is minor compared to the next point.2. Irregularity: Unused/Redundant Logic & Readability
Suggestion:
In the loop:
If
field == "auth_config"butlicense_validisFalseorvalueis not adict, thecontinueskips thesetattr. This is correct.However, if
field != "auth_config", it executessetattr(portal, field, value)immediately after theifblock.This structure is slightly hard to follow because
setattris conditional on not entering theauth_configblock OR successfully passing the checks insideauth_config.A clearer structure:
Verdict: Your current logic is functionally equivalent but slightly less readable than the above. It works, but separating the
setattrmakes the flow of control clearer.3. Optimization: Set Initialization
Suggestion:
Change
file_fields = ["logo", "id", "create_time", "update_time"](which was changed to a set) is good.Ensure
file_fieldsis indeed a set. If it’s a tuple/list, membership testing is O(n). A set is O(1).In the diff:
file_fields = {"logo", "id", "create_time", "update_time"}is a set literal. Good optimization.4. Potential Bug:
instance.items()and File UploadsCritical Check:
How are file uploads handled in
instance?Typically, Django ModelForms or Serializers handle files via
request.FILES.If
instanceis a dictionary representingrequest.DATAor a JSON payload,instance.get("logo")will likely return a string path, URL, orNone, not a file object.Your
_handle_file_field(portal, field_name, instance.get(field_name))expects a file-like object.If
instanceis from a JSON API, you won't be able to upload a new logo unless your custom serializer/view correctly extracts the file from the multipart request and puts it intoinstanceas anUploadedFileobject before callingedit.Recommendation: Verify that
self._handle_file_fieldreceives a valid file object. If this endpoint is JSON-only, logo updates will fail silently or raise an error when trying to save a string to the file field.5. Optimization: Early Return / Guard Clauses
The current
if portal is None: raise...is fine.6. Consistency: Return Value
You replaced
return PortalSerializer.Model(portal).datawithreturn self.one().self.one()ensures consistency with other methods (likeretrieve) to avoid duplicate serialization logic.self.one()fetches the fresh instance from the DB (it should, since it's called afterportal.save()). Ifself.one()calls a separate query, it is safe. If it relies on cached state, it might be stale. Usually,.one()in such contexts re-fetches. Likely Good.7. Security/Maintenance: License Check Caching
self._is_license_valid()is called once and stored inlicense_valid. Good practice. Avoid redundant license logic calls.Refactored Suggestion (Improving Readability)
Summary of Findings
auth_configis correct but slightly dense; refactoring improves readability.setforignored_fieldsis a good optimization.instance["logo"]. If this is a JSON API,instance.get("logo")is likely invalid for_handle_file_field. Ensure your middleware/serializer maps multipart form data to the dictionary correctly.self.one()is better for DRY principles than manual serialization.