mawoka-myblock / ClassQuiz

ClassQuiz is a quiz-application like Kahoot!, but open-source.
https://classquiz.de
Mozilla Public License 2.0
479 stars 85 forks source link

:bug: Update models.py to make them compatible with current Ormar and Pydantic #383

Closed BogPlaymate closed 5 months ago

BogPlaymate commented 5 months ago

Changes are required to work with the current version of ormar (i.e. migrate to ormar 0.20 and above). From the ormar documentation:

"Instead of defining a Meta class now each of the ormar models require an ormar_config parameter that is an instance of the OrmarConfig class. Note that the attribute must be named ormar_config and be an instance of the config class." https://collerek.github.io/ormar/latest/migration/

All the "Meta" nested classes have been removed, and instead the fields implemented in OrmarConfig objects.

Additionally, a Config class, which was previous nested in the User class, has also been removed. The existence of this resulted in a Pydantic error: "pydantic.errors.PydanticUserError: "Config" and "model_config" cannot be used together".

This class only held one value: class Config: use_enum_values = True

As far as I know, the above Config class is not used anywhere. When I searched the project for any references to "use_enum_values", I did not find anything. However, it is possible that I am misunderstanding its use.

Thank you for reading this. These changes are required to build the project with current libraries. Hopefully they will help new developers, and old developers who do a clean install.

:tophat: What? Why?

As above

:pushpin: Related Issues

As above

Testing

The way to test it is to upgrade the ormar and pydantic libraries on your computer.

:clipboard: Checklist

⚠️ No tests suites for now ⚠️ :rotating_light: Please review the guidelines for contributing to this repository.

:camera: Screenshots

Please let me know if screenshots would be helpful

:hearts: Thank you!

mawoka-myblock commented 5 months ago

Thank you soo much for this PR! I'll take a closer look soon! Regarding the enum config flag:

As far as I remember, this tells/told ormar to map the enum to the custom enum type in the db, so it doesn't store strings or numbers, but I don't know what happened to that in current ormar.

BogPlaymate commented 5 months ago

:) Well, thank you so much for the warm reply!

In order to get the project working with current Orman and Pydantic, this is the models.py that I use. However, maybe I might have made other small changes to other files. If you do try upgrading Orman/Pydantic, and you get errors, please tell me! I probably have the solutions on my computer.

Please have a nice day.

On Thu, Jul 4, 2024, 20:19 Marlon @.***> wrote:

Thank you soo much for this PR! I'll take a closer look soon! Regarding the enum config flag:

As far as I remember, this tells/told ormar to map the enum to the custom enum type in the db, so it doesn't store strings or numbers, but I don't know what happened to that in current ormar.

— Reply to this email directly, view it on GitHub https://github.com/mawoka-myblock/ClassQuiz/pull/383#issuecomment-2208723034, or unsubscribe https://github.com/notifications/unsubscribe-auth/BAUGNECSRJVZFIIPSNVSKADZKUVTBAVCNFSM6AAAAABKLKVOPSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMBYG4ZDGMBTGQ . You are receiving this because you authored the thread.Message ID: @.***>

mawoka-myblock commented 5 months ago

Please also commit all the other changed files, so that'll be easier. It doesn't matter if they are janky, we'll address those together.

BogPlaymate commented 5 months ago

That sounds interesting.

I've reviewed the files which I changed. I do believe that the models.py files is the only file I changed as relates to ormar. Pydantic gave me so many errors, I can't quite remember if other changes will be necessary to meet the requirements of the current version.

I did make various other changes. One of them is required to work with the current version of redis. However, these are probably better addressed in a separate commit?

On Thu, Jul 4, 2024 at 10:32 PM Marlon @.***> wrote:

Please also commit all the other changed files, so that'll be easier. It doesn't matter if they are janky, we'll address those together.

— Reply to this email directly, view it on GitHub https://github.com/mawoka-myblock/ClassQuiz/pull/383#issuecomment-2208998837, or unsubscribe https://github.com/notifications/unsubscribe-auth/BAUGNEFXFD4TADIHOGGGTBTZKVFF5AVCNFSM6AAAAABKLKVOPSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMBYHE4TQOBTG4 . You are receiving this because you authored the thread.Message ID: @.***>

BogPlaymate commented 5 months ago

To clarify, I mean there may be other changes to work with the current version of pydantic. I am fairly confident the models.py file will be enough to make the project compatible with ormar.

On Fri, Jul 5, 2024 at 5:56 AM Joe Fox @.***> wrote:

That sounds interesting.

I've reviewed the files which I changed. I do believe that the models.py files is the only file I changed as relates to ormar. Pydantic gave me so many errors, I can't quite remember if other changes will be necessary to meet the requirements of the current version.

I did make various other changes. One of them is required to work with the current version of redis. However, these are probably better addressed in a separate commit?

On Thu, Jul 4, 2024 at 10:32 PM Marlon @.***> wrote:

Please also commit all the other changed files, so that'll be easier. It doesn't matter if they are janky, we'll address those together.

— Reply to this email directly, view it on GitHub https://github.com/mawoka-myblock/ClassQuiz/pull/383#issuecomment-2208998837, or unsubscribe https://github.com/notifications/unsubscribe-auth/BAUGNEFXFD4TADIHOGGGTBTZKVFF5AVCNFSM6AAAAABKLKVOPSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMBYHE4TQOBTG4 . You are receiving this because you authored the thread.Message ID: @.***>

mawoka-myblock commented 5 months ago

Yea, but please also push the Pipfile and the Pipfile.lock. But when we upgrade pydantic and ormar, all imports will have to be updated to use the V1 and the gradually update from there for all the other pydantic usages throughout ClassQuiz.

BogPlaymate commented 5 months ago

I will find out how to push the pipfile and pipfile.lock now.

On Fri, Jul 5, 2024 at 6:14 AM Marlon @.***> wrote:

Yea, but please also push the Pipfile and the Pipfile.lock. But when we upgrade pydantic and ormar, all imports will have to be updated to use the V1 and the gradually update from there for all the other pydantic usages throughout ClassQuiz.

— Reply to this email directly, view it on GitHub https://github.com/mawoka-myblock/ClassQuiz/pull/383#issuecomment-2209568767, or unsubscribe https://github.com/notifications/unsubscribe-auth/BAUGNEBAFZ4YN4H3FH4BQGTZKW3LLAVCNFSM6AAAAABKLKVOPSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMBZGU3DQNZWG4 . You are receiving this because you authored the thread.Message ID: @.***>

mawoka-myblock commented 5 months ago

git add Pipfile, git add Pipfile.lock, git commit -m ":sparkles: Updated Pipfile & git push

BogPlaymate commented 5 months ago

Thank you for the command line instructions. I tried using them, and after logging on I get:

"On branch master Your branch is up to date with 'origin/master'.

Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git restore ..." to discard changes in working directory) modified: Caddyfile modified: classquiz/config.py modified: classquiz/db/models.py modified: classquiz/routers/login.py modified: classquiz/routers/quiz.py modified: classquiz/routers/sitemap.py modified: classquiz/worker/init.py modified: docker-compose.yml modified: frontend/Dockerfile modified: frontend/package.json modified: frontend/pnpm-lock.yaml modified: frontend/src/lib/components/commandpalette.svelte modified: frontend/src/routes/+page.svelte modified: frontend/src/routes/account/login/select_method.svelte modified: frontend/src/routes/account/login/start_window.svelte modified: frontend/vite.config.js

Untracked files: (use "git add ..." to include in what will be committed) classquiz/config (copy).py classquiz/db/models (copy).py classquiz/routers/sitemap (copy).py docker-compose (copy).yml frontend/Dockerfile (copy) frontend/package (copy).json frontend/src/lib/components/BACKUPcommandpalette (copy).svelteBACKUP frontend/src/routes/BACKUP+page (copy).svelteBACKUP frontend/src/routes/account/login/BACKUPselect_method (copy).svelteBACKUP frontend/src/routes/account/login/BACKUPstart_window (copy).svelteBACKUP frontend/vite.config (copy).js run_tests2.sh temptest.sh"

Previously I was using the browser interface, sorry!

mawoka-myblock commented 5 months ago

Okay, then for now just run git add . and then the commit and push command. This should upload all your changes here. Even though that may not be what you want, there's always time for cleanup which I'll be assisting with tomorrow while you're at sleep ;)

BogPlaymate commented 5 months ago

Thank you. You are too kind. I will be home from work in about 11 hours from now.

I'm having some difficulty authenticating myself via the command line (apparently you cannot do it via password anymore!) Hopefully I will be able to resolve this soon before I leave for work.

mawoka-myblock commented 5 months ago

Yes, that's true. You could also try using ssh, but GitHub has some good docs about that, so I'm sure you'll manage that!

BogPlaymate commented 5 months ago

:) At least I should be able to log on to github, right?

mawoka-myblock commented 5 months ago

The easiest way seems to be to use the github CLI and run the following command: https://cli.github.com/manual/gh_auth_login

BogPlaymate commented 5 months ago

Alright, so I'm authenticated on github.

But, the push command gives:

"remote: Permission to mawoka-myblock/ClassQuiz.git denied to BogPlaymate. fatal: unable to access 'https://github.com/mawoka-myblock/ClassQuiz/': The requested URL returned error: 403"

Is this because it's pushing to the wrong place (i.e. the main repository)? Or alternatively it may be because additional authentication is required...

On Fri, Jul 5, 2024 at 6:39 AM Marlon @.***> wrote:

The easiest way seems to be to use the github CLI and run the following command: https://cli.github.com/manual/gh_auth_login

— Reply to this email directly, view it on GitHub https://github.com/mawoka-myblock/ClassQuiz/pull/383#issuecomment-2209583763, or unsubscribe https://github.com/notifications/unsubscribe-auth/BAUGNECU63Y2ZIRZA4ARU4LZKW6HTAVCNFSM6AAAAABKLKVOPSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMBZGU4DGNZWGM . You are receiving this because you authored the thread.Message ID: @.***>

BogPlaymate commented 5 months ago

Anyway, thank you for your help late at night. About the time you wake up, I will get back from work and start trying to reveal my code.

On Fri, Jul 5, 2024 at 6:45 AM Joe Fox @.***> wrote:

Alright, so I'm authenticated on github.

But, the push command gives:

"remote: Permission to mawoka-myblock/ClassQuiz.git denied to BogPlaymate. fatal: unable to access 'https://github.com/mawoka-myblock/ClassQuiz/': The requested URL returned error: 403"

Is this because it's pushing to the wrong place (i.e. the main repository)? Or alternatively it may be because additional authentication is required...

On Fri, Jul 5, 2024 at 6:39 AM Marlon @.***> wrote:

The easiest way seems to be to use the github CLI and run the following command: https://cli.github.com/manual/gh_auth_login

— Reply to this email directly, view it on GitHub https://github.com/mawoka-myblock/ClassQuiz/pull/383#issuecomment-2209583763, or unsubscribe https://github.com/notifications/unsubscribe-auth/BAUGNECU63Y2ZIRZA4ARU4LZKW6HTAVCNFSM6AAAAABKLKVOPSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMBZGU4DGNZWGM . You are receiving this because you authored the thread.Message ID: @.***>

mawoka-myblock commented 5 months ago

Yes, exactly. You have to run "git remote add fork https://github.com/BlogPlaymate/ClassQuiz" and then push with "git push -u fork"

BogPlaymate commented 5 months ago

Brilliant, thank you. I looked it up, but actually the commands you suggest seem much more concise. Right now I'm at my workplace. I will be home in about two hours and thirty minutes.

On Fri, Jul 5, 2024 at 2:05 PM Marlon @.***> wrote:

Yes, exactly. You have to run "git remote add fork https://github.com/BlogPlaymate/ClassQuiz" and then push with "git push -u fork"

— Reply to this email directly, view it on GitHub https://github.com/mawoka-myblock/ClassQuiz/pull/383#issuecomment-2210180145, or unsubscribe https://github.com/notifications/unsubscribe-auth/BAUGNEESKOB26FUNX46P7C3ZKYSR7AVCNFSM6AAAAABKLKVOPSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMJQGE4DAMJUGU . You are receiving this because you authored the thread.Message ID: @.***>

BogPlaymate commented 5 months ago

Sorry, I had to work late at the school. My apologies.

NOW We have both made a small mistake. And its not clear how to undo it. My username is "BogPlaymate", however, we spelled it wrong, and now...I can't seem to add the right fork....

See below. The first command is correct, with "Bog". However, the fork "Blog" is attached, and this url in fact does not exist.

@.:~/ClassQuiz$ git remote add fork https://github.com/BogPlaymate/ClassQuiz error: remote fork already exists. @.:~/ClassQuiz$ git remote -v fork https://github.com/BlogPlaymate/ClassQuiz (fetch) fork https://github.com/BlogPlaymate/ClassQuiz (push) origin https://github.com/mawoka-myblock/ClassQuiz (fetch) origin https://github.com/mawoka-myblock/ClassQuiz (push)

On Fri, Jul 5, 2024 at 2:13 PM Joe Fox @.***> wrote:

Brilliant, thank you. I looked it up, but actually the commands you suggest seem much more concise. Right now I'm at my workplace. I will be home in about two hours and thirty minutes.

On Fri, Jul 5, 2024 at 2:05 PM Marlon @.***> wrote:

Yes, exactly. You have to run "git remote add fork https://github.com/BlogPlaymate/ClassQuiz" and then push with "git push -u fork"

— Reply to this email directly, view it on GitHub https://github.com/mawoka-myblock/ClassQuiz/pull/383#issuecomment-2210180145, or unsubscribe https://github.com/notifications/unsubscribe-auth/BAUGNEESKOB26FUNX46P7C3ZKYSR7AVCNFSM6AAAAABKLKVOPSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMJQGE4DAMJUGU . You are receiving this because you authored the thread.Message ID: @.***>

mawoka-myblock commented 5 months ago

Oh, ofc, it should have been BogPlaymate, my bad. You can remove the remote by running git remote rm fork and add it back correclty by running git remote add fork https://github.com/logPlaymate/ClassQuiz.git

BogPlaymate commented 5 months ago

Hi. I've uploaded everything. The commands helped. So, if you want, you can see the complete picture. It is not linted and doesn't look nice yet though.

On Fri, Jul 5, 2024 at 6:46 PM Marlon @.***> wrote:

Oh, ofc, it should have been BogPlaymate, my bad. You can remove the remote by running git remote rm fork and add it back correclty by running git remote add fork https://github.com/logPlaymate/ClassQuiz.git

— Reply to this email directly, view it on GitHub https://github.com/mawoka-myblock/ClassQuiz/pull/383#issuecomment-2210560836, or unsubscribe https://github.com/notifications/unsubscribe-auth/BAUGNECDV4VFIAFHL3YL2KTZKZTRBAVCNFSM6AAAAABKLKVOPSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMJQGU3DAOBTGY . You are receiving this because you modified the open/close state.Message ID: @.***>

mawoka-myblock commented 5 months ago

Just push it. I'll fix the linting errors, etc

mawoka-myblock commented 5 months ago

That's what draft PRs are for