ZA | 25-SDC-JULY | Luke Manyamazi | Sprint 1 | New Feature Rebloom - #58
ZA | 25-SDC-JULY | Luke Manyamazi | Sprint 1 | New Feature Rebloom#58Luke-Manyamazi wants to merge 0 commit into
Conversation
| # Returning 0 or raising an error are typical ways to indicate failure | ||
| return 0 |
There was a problem hiding this comment.
I don't think any other code in this codebases uses magic return values to indicate errors, and the code that calls this doesn't pass this error back to the client. You need to handle errors differently here.
There was a problem hiding this comment.
Good point — using magic return values hides failures from the caller.
I’ve refactored the rebloom logic to raise exceptions instead.
| print(f"Error adding rebloom: User with ID {user_id} not found.") | ||
| return None |
There was a problem hiding this comment.
This doesn't bubble the error back up to the caller - the caller will need to know this failed.
This applies throughout your change.
| }) | ||
|
|
||
| @jwt_required() | ||
| def check_rebloom_status(bloom_id_str): |
There was a problem hiding this comment.
What are the trade-offs of having this be a stand-alone function that's called per bloom vs including this information up-front when getting a list of blooms?
| try: | ||
| # First create the new bloom | ||
| rebloom_bloom_id = add_bloom( | ||
| sender=sender_user, # <<< Use the fully hydrated User object |
There was a problem hiding this comment.
AFAICT add_bloom only actually uses the sender ID, an no other data from the sender - might it be simpler to make add_bloom take just the id, and change the other call-sites from sender to sender.id, rather than needing to add a whole extra database roundtrip to turn the sender ID into a sender, just to take only the ID back out of it?
| This is necessary for operations like reblooming where only the ID is known. | ||
| """ | ||
| with db_cursor() as cur: | ||
| # NOTE: Adjust column names if they are different in your 'users' table |
There was a problem hiding this comment.
What does this comment mean?
| rebloom_id = blooms.add_rebloom( | ||
| user_id=current_user.id, | ||
| original_bloom_id=bloom_id, | ||
| content=original_bloom.content # FIX: .content not ['content'] |
There was a problem hiding this comment.
What is this comment about?
| app.json = CustomJsonProvider(app) | ||
|
|
||
| # Configure CORS to handle preflight requests | ||
| # --- CORS FIX APPLIED HERE --- |
There was a problem hiding this comment.
Things seemed to be working ok without this change - why did you need to change it?
| ); | ||
|
|
||
| -- Add rebloom_count to blooms table (to track total reblooms) | ||
| ALTER TABLE blooms ADD COLUMN rebloom_count INTEGER DEFAULT 0; |
There was a problem hiding this comment.
Ideally you wouldn't need to track rebloom counts in the database - there is a race condition here where values can get out of date (e.g. if you create a rebloom but haven't updated this count yet).
Instead, use SQL relationships to compute this - in a query, you should be able to compute the count of blooms which have this ID as an original_bloom_id
Your Python and JS code for querying a Bloom shouldn't have to change, but it removes the need for you to update the original bloom from the python side.
| ALTER TABLE blooms ADD COLUMN original_bloom_id BIGINT REFERENCES blooms(id); | ||
|
|
||
| -- Create reblooms table to track the rebloom relationship | ||
| CREATE TABLE reblooms ( |
There was a problem hiding this comment.
This table shouldn't need to exist - all of the information should already be present in the blooms table for you to do some joins to infer this information.
There was a problem hiding this comment.
As far as I can tell this table isn't used any more, but it's still created? Please remove.
|
|
||
| const rebloomIndicator = document.createElement('div'); | ||
| rebloomIndicator.className = 'rebloom-indicator'; | ||
| rebloomIndicator.innerHTML = ` |
There was a problem hiding this comment.
There's an XSS vulnerability here by using innerHTML
|
Hi Daniel I have done the following:
|
illicitonion
left a comment
There was a problem hiding this comment.
A lot of this is looking a lot better, but there's still a lot of unrelated changes in here, and a bunch of unused code. Please take a look, and make sure:
- You've addressed and resolved all comments.
- All of the code in this PR is needed and related to this change.
It's much harder for a reviewer to see if your code is working or look for issues when half of the change isn't related.
There was a problem hiding this comment.
This file seems to have a lot of unrelated changes to it?
|
|
||
| already_rebloomed = blooms.has_user_rebloomed(current_user.id, bloom_id) | ||
|
|
||
| if already_rebloomed: |
There was a problem hiding this comment.
This kind of "toggle" behaviour can be complicated to support well in clients - they may retry requests (e.g. if the network blipped) which can accidentally undo changes.
In general I'd recommend API design where a user clearly expresses intent to rebloom or un-rebloom something, and will get an error if that's not possible, rather than sometimes undoing the action. The UI can re-use the same button, but it should typically talk to a different backend endpoint.
| ALTER TABLE blooms ADD COLUMN original_bloom_id BIGINT REFERENCES blooms(id); | ||
|
|
||
| -- Create reblooms table to track the rebloom relationship | ||
| CREATE TABLE reblooms ( |
There was a problem hiding this comment.
As far as I can tell this table isn't used any more, but it's still created? Please remove.
dca08db to
921f365
Compare
|
Mistakenly closed this PR |
|
Opening it to finish with review edits |
illicitonion
left a comment
There was a problem hiding this comment.
This generally looks decent, but it doesn't look like it works for me?
I ran it locally, and when I first logged in I got an error prompt.
I dismissed it and tried to rebloom something, and got an error alert" Unexpected token '<', "<!DOCTYPE "... is not valid JSON
67513e4 to
3c9f07b
Compare
|
"Hi Daniel, I’ve refactored the Rebloom feature to address your feedback: Fixed XSS: Replaced innerHTML with createTextNode for safe rendering. Removed Race Conditions: rebloom_count is now calculated via SQL subqueries instead of a manual column. JSON Fix: Standardized all error responses to jsonify() to resolve the Unexpected token < crash. Efficiency: Streamlined add_bloom to accept sender_id directly, removing redundant DB lookups. |
|
Hi Daniel, I was getting an error while trying to rebloom, but it's fixed now. Here’s a summary of the changes: Fix: Rebloom Functionality & Auth Persistence |
e9a955d to
921f365
Compare
Learners, PR Template
Self checklist
Changelist
Questions
Ask any questions you have for your reviewer.