-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feature/user registration schema changes #15
Feature/user registration schema changes #15
Conversation
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.
This MR is too big for an effective review.
We should split into smaller chunks.
Feedback loop is going to be too big.
@@ -240,7 +240,35 @@ Add a new database migration | |||
``` | |||
flask db migrate -m "Schema" | |||
flask db migrate -m "Add unique constraint to Ad model" | |||
flask db migrate -m "Add account changes" |
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.
Why this log?
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.
Not a log, I copy/pasted and left it there 👯
cd backend | ||
docker build -t img-local-poetry -f backend/dockerfile-apiserver-local ./backend | ||
docker run -it --rm -v %cd%:/app -w /app img-local-poetry /bin/bash -c "poetry lock" | ||
|
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.
I do a little differently. I would say the added complexity is not needed.
There is a docker-compose file just for development.
justo do:
docker-compose exec app bash
Once inside the container do all the needed commands.
Env file looks a bit like this.
ENVIRONMENT=DEV
MYSQL_ROOT_PASSWORD=passowrd
MYSQL_PASSWORD=12345
MYSQL_USER=vinhos
MYSQL_DATABASE=vinhos_dev
MYSQL_HOST=db
MYSQL_PORT=3306
TIMEZONE=Europe/Lisbon
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.
This was to solve the error of a poetry dependency "poetry 'HTTPResponse' object has no attribute 'strict'".
It is a recent issue and a pain to solve.
python-poetry/poetry#7936
With docker compose, you caanot run the command "poetry lock" because the container "apiserver" does not start
@@ -69,11 +69,12 @@ def _to_dict(self): | |||
for column in inspect(self.__class__).attrs | |||
} | |||
|
|||
def save(self): | |||
def save(self, refresh=False): |
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.
why the option refresh=False
? To retrieve the schema?
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.
yes, after insert, you want to get the ID of the record that was inserted.
|
||
account_name = db.Column(db.String(50), unique=True, nullable=False) | ||
account_name = db.Column(db.String(60), nullable=True, comment="Account can have any name, it is an internal reference") |
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.
Why is the field nullable?
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.
It will be managed by store name, this will be a internal reference field.
@@ -16,10 +16,11 @@ class Account(db.Model, BaseModel, metaclass=MetaBaseModel): | |||
|
|||
id = db.Column(db.BigInteger(), primary_key=True, nullable=False) | |||
status_id = db.Column(db.Integer(), default=StatusType.NEW, nullable=False, comment="Status id") | |||
address_id = db.Column(db.BigInteger(), nullable=False, comment="Address id") | |||
address_id = db.Column(db.BigInteger(), nullable=True, comment="Address id") |
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.
Isn't the adress required?
Why is address in a different schema? This will result in a one to many relation. On the other hand ther will be the possibility of multiple adresses having the same account. Is this what we want?
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.
Yes, this will be like Ebay, we have the billing address, delivery address, dispatch address if necessary and store addresses.
One account can have several stores.
One account will be able to manage several addresses and each address is associated with an entity.
"invalid": "email-invalid-type", | ||
"type": "email-invalid-must-be-string"}) | ||
|
||
# account_id = fields.Int(required=True) |
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.
Commented please remove.
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.
ok
@@ -31,39 +45,45 @@ def update(user: User, **kwargs) -> User: | |||
return user.save() |
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.
SAving on get_by
. This is probably wrong.
user_result = user.save(refresh=True) | ||
except (IntegrityError, PyMySQLIntegrityError) as e: | ||
user_result = None | ||
abort(400, _("A user with this email already exists. Please use a different email.")) |
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.
This is wrong. The error might not error due to email only. :D
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.
Email is unique for login purposes to identify the user.
except (IntegrityError, PyMySQLIntegrityError) as e: | ||
user_result = None | ||
abort(400, _("A user with this email already exists. Please use a different email.")) | ||
except Exception as e: |
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.
We should not catch on broad exceptions.
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.
This is a special case because of the password_hash.
I dont want to log anything in this part.
@@ -16,34 +17,35 @@ def post(self): | |||
resource_parser = reqparse.RequestParser(trim=True, bundle_errors=True) | |||
|
|||
# Add arguments | |||
# resource_parser.add_argument( |
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.
remove comments.
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.
ok
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.
This MR is too big for an effective review.
We should split into smaller chunks.
Feedback loop is going to be too big.
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.
This MR is too big for an effective review.
We should split into smaller chunks.
Feedback loop is going to be too big.
No description provided.