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

feat: theme config draft api implementation #246

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tehreem-sadat
Copy link
Collaborator

@tehreem-sadat tehreem-sadat commented Feb 27, 2025

Description:

Draft config api implementation for get,update,delete

Related Issue:

#240
#241
#243

@tehreem-sadat tehreem-sadat changed the title feat: theme config drfat api implementation feat: theme config draft api implementation Feb 27, 2025
@tehreem-sadat tehreem-sadat force-pushed the tehreem/theme_config_draft_api_implementation branch from 7672fa3 to 47ff729 Compare February 28, 2025 03:35
Copy link
Collaborator

@shadinaif shadinaif left a comment

Choose a reason for hiding this comment

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

thank you @tehreem-sadat for handling this critical PR. Please check my comments

"""Get draft config"""

updated_fields = get_draft_tenant_config(int(tenant_id))
dict_str = json.dumps(updated_fields, sort_keys=True, separators=(',', ':')) if updated_fields else ''
Copy link
Collaborator

Choose a reason for hiding this comment

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

please move the dump and the hashing to a function. You're going to need it when you implement publish API

)

new_value = data.get('new_value')
reset = data.get('reset', False)
Copy link
Collaborator

Choose a reason for hiding this comment

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

please change this to 0 and 1 as like other flags we have (ex. include_staff)

Comment on lines +1260 to +1267
if not reset and not new_value:
raise FXCodedException(
code=FXExceptionCodes.INVALID_INPUT, message='Provide either new_value or reset.'
)
if new_value and not isinstance(new_value, type(data['current_value'])):
raise FXCodedException(
code=FXExceptionCodes.INVALID_INPUT, message='New value type must match current value.'
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

these validations are great, but here we have a hidden bug. new_value might exist but have None as a value. Same for current_value; it can be None (which will cause an exception every time we call the API for that key)

I'll move the discussion to slack, then we post here our discussion: will we allow None for config values or not

:return: A dictionary with the updated fields and their new values.
:rtype: dict
"""
config = get_all_tenants_info()['config'].get(tenant_id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

well, this is one of the cases that we must not use the cache 🥲 . We need to keep safe editing in lms_config, so we'll have to always fetch from database

message='Invalid path for key: ({key_access_info.key}), path: ({key_access_info.path}) '
'as it does not exist in tenant config for tenant or maybe its value is empty: {tenant_id}.'
)
if stored_value != current_value:
Copy link
Collaborator

Choose a reason for hiding this comment

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

we can let MySQL handle the comparison while updating the key. This is good, but it'll not guarantee error detection for parallel write commands

tenant = TenantConfig.objects.get(id=tenant_id)
tenant.lms_configs['config_draft'] = draft_config
tenant.save()
invalidate_cache()
Copy link
Collaborator

Choose a reason for hiding this comment

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

related to not using cache comment; invalidating the cache might jeopardize the dashboard when the designer started to be frequently used. Imaging an empty new tenant with one admin user playing with the designer for a couple of hours. No cache for hundreds of other admins within that period

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