Sheffield | 25-SDC-Nov | Hassan Osman | Sprint 1 | Bug Report: Extra long blooms?#147
Sheffield | 25-SDC-Nov | Hassan Osman | Sprint 1 | Bug Report: Extra long blooms?#147HassanOHOsman wants to merge 14 commits intoCodeYourFuture:mainfrom
Conversation
OracPrime
left a comment
There was a problem hiding this comment.
Convince me of your approach (good luck!) or make it fail not trim!
front-end/components/bloom-form.mjs
Outdated
| const originalText = submitButton.textContent; | ||
| const textarea = form.querySelector("textarea"); | ||
| const content = textarea.value.trim(); | ||
| const content = textarea.value.trim().slice(0, 280); |
There was a problem hiding this comment.
I'm not convinced. Should too long a bloom fail, or should you truncate it and accept it? I think it should fail.
There was a problem hiding this comment.
To be honest, at the time I was in two minds whether or not to handle the too long bloom with an error which lead to it not being submitted. However, somehow eventually I resorted to chopping the extra characters. I perhaps thought this approach would me more ideal since it's already published bloom.
I understand now I have to fail it altogether. I will working on it. Thank you.
… will later be replaced with a logic that fails the bloom altogeather.
… the console. Use it to skip it while fetching all blooms from backend
…en blooms fetched from backend
|
AS bloom - the one over 280 character is now hidden. Not sure if it's the ideal approach but I did use the bloom id from the error message showed up on my browser and used it to skip over the culprit bloom when blooms are being fetched. |
|
I understand very well that, ideally, there should've been a condition that'd check if a bloom was over 280 characters and if so it'd be skipped over. Having said that this just didn't work for some reason when i did it. |
|
UPDATE: Well, it has worked now - I replaced the bloom ID-based logic to a conditional logic that checks if bloom is over 280 char and skips over it if that's the case. I had to disconnect from all ports and reconnect again. |
OracPrime
left a comment
There was a problem hiding this comment.
You seem to be prevent overlong blooms being displayed when reading them back from the database. This is the wrong time to be doing it. You need to prevent overlong blooms being added.
I'm also concerned that your code refers to a non-existent function. Have you tested this?
backend/data/blooms.py
Outdated
|
|
||
| def get_bloom(bloom_id: int) -> Optional[Bloom]: | ||
| with db_cursor() as cur: | ||
| with db_get_bloomcursor() as cur: |
There was a problem hiding this comment.
This function doesn't exist does it?
There was a problem hiding this comment.
I have not implemented unit tests. However, i have manually tested what i did through the browser. Everything seemed fine, the culprit bloom wasn't/isn't displayed (which - I now know - is not the right way to do it), clicked on different buttons, sent a bloom so basically did different operations and no error messages showed up whatsoever in the console. I've attached screenshots for reference.
As for the non-existent function, I can't recall how that happen but I got it to how it was.
|
All done now. filtered out long blooms just before they're being send back to clients' browsers. |
| all_blooms = followed_blooms + own_blooms | ||
|
|
||
| # Filter long blooms (over 280 characters) | ||
| all_blooms = [bloom for bloom in all_blooms if len(bloom.content) <= MAX_BLOOM_LENGTH] |
There was a problem hiding this comment.
You're filtering blooms that are already in the backend that are over MAX_BLOOM_LENGTH but you're doing nothing to stop new ones being added.
There was a problem hiding this comment.
I actually initially added a length checker inside the add_bloom function to make the logic future-proof. However, I then thought that from the client side users can’t go beyond 280 characters anyway. I know this isn’t the correct way to approach it, since someone could bypass the frontend and send a longer bloom directly to the server. I honestly focused solely on meeting the exact requirements of the quiz, which isn’t best practice. I know should fix not just the stated problem but also any potential loopholes that could cause issues in the future.
|
Done! |
OracPrime
left a comment
There was a problem hiding this comment.
I think we've got there. Couple of comments to read/understand, but I think we can move on from this exercise. Remember: check on the way in, trust no-one.
| hashtags = [word[1:] for word in content.split(" ") if word.startswith("#")] | ||
|
|
||
| now = datetime.datetime.now(tz=datetime.UTC) | ||
| bloom_id = int(now.timestamp() * 1000000) |
There was a problem hiding this comment.
This is sort of OK. But there are two better ways. Either investigate uuid.uuid4() or database autoincrement fields. In the context of this exercise, given that we're not going deep into databases, probably the uuid route.
There was a problem hiding this comment.
Clearly this is nothing to do with the 280 char limit, so I mention this as a comment for your learning, not a request to fix it
Noted. Thank you very much! |
Self checklist
This PR fixes AS's extra long bloom bug by ensuring it respects the 280-character limit. Changes include: