profile
viewpoint
If you are wondering where the data of this site comes from, please visit https://api.github.com/users/aalvrz/events. GitMemory does not store any data, but only uses NGINX to cache data for a period of time. The idea behind GitMemory is simply to give users a better reading experience.
Andrés Álvarez aalvrz Honduras aalvarez.me :snake: Python Engineer

aalvrz/Hourglass 6

:hourglass: Track time spent on your favorite activities

aalvrz/google-interview-university 1

A complete daily plan for studying to become a Google software engineer.

aalvrz/ace 0

Ace (Ajax.org Cloud9 Editor)

aalvrz/ADA-Compiler 0

:coffee: Ada language compiler written in Java that features lexical and syntax analysis using JFlex and JavaCup.

aalvrz/advent-of-code 0

⭐ My Advent of Code solutions

aalvrz/ant-design 0

🐜 A UI Design Language

aalvrz/awesome-hacking-spots 0

:computer: :coffee: List of Awesome Hacking places, orgaty, listing if it features power and wifi

aalvrz/aws-sdk-java 0

The official AWS SDK for Java.

aalvrz/boto3 0

AWS SDK for Python

aalvrz/chalice 0

Python Serverless Microframework for AWS

issue openedsqlalchemy/sqlalchemy

Existing records are altered unintentionally when

Describe the bug

I am not sure if this is a MySQL bug or SQLAlchemy bug but I figured I would try reporting this here.

In my unit tests I am instantiating and committing some objects from a model and I am passing an already persisted team object as relationship on instantiation. However each subsequent creation sets the previous entry's team (or team_id FK) to NULL for some unknown reason!

To Reproduce

site_1 = SiteFactory(team=team)
sa_1 = SiteAccess(site=site_1, team=team, permission=1)
session.add(sa_1)
session.commit()


This creates the `SiteAccess` entry without any problems, but if I create another one with another site but same team, the `team_id` column from the record above (`sa_1`) is set to NULL 🤯 🤯 🤯 :

```python
site_2 = SiteFactory(team=team)
sa_2 = SiteAccess(site=site_2, team=team, permission=1)
session.add(sa_2)
session.commit()
|id |site_id|user_id|team_id|permission|expiration_date|created_at         |is_deleted|
|---|-------|-------|-------|----------|---------------|-------------------|----------|
|1  |2593   |       |       |1         |               |2021-09-22 18:02:00|0         |
|2  |2594   |       |367    |1         |               |2021-09-22 18:02:21|0         |


### Error

No errors

### Versions

- OS: Ubuntu 21.04
- Python: 3.9.5
- SQLAlchemy: 1.3.18
- Database: MySQL 5.7
- DBAPI: PyMySQL==0.10.0


### Additional context

Here is the model declaration:

```python
class SiteAccess(Base, DeletableModel):
    __tablename__ = "site_access"
    __table_args__ = (
        UniqueConstraint("site_id", "user_id"),
        UniqueConstraint("site_id", "team_id"),
    )

    id = Column(INTEGER(10), primary_key=True)
    site_id = Column(ForeignKey("company.company_id"), nullable=False, index=True)
    user_id = Column(ForeignKey("users.user_id"))
    team_id = Column(ForeignKey("team.group_id"))
    permission = Column(TINYINT(1), nullable=False)
    expiration_date = Column(DateTime)

    created_at = Column(DateTime, nullable=False, default=datetime.utcnow)

    site = relationship("Site")
    user = relationship("User", backref=backref("site_access", uselist=False))
    team = relationship("Team", backref=backref("site_access", uselist=False))

I don't know if there is something wrong with the declaration to allow something like this to happen.

Here is the DDL:

CREATE TABLE `site_access` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `site_id` int(10) unsigned NOT NULL,
  `user_id` int(10) unsigned DEFAULT NULL,
  `team_id` int(10) unsigned DEFAULT NULL,
  `permission` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `expiration_date` datetime DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `is_deleted` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_site_and_user_ids` (`site_id`,`user_id`),
  UNIQUE KEY `unique_site_and_team_ids` (`site_id`,`team_id`),
  KEY `user_id` (`user_id`),
  KEY `team_id` (`team_id`),
  CONSTRAINT `fk_site_access_siteid` FOREIGN KEY (`site_id`) REFERENCES `company` (`company_id`) ON DELETE CASCADE,
  CONSTRAINT `site_access_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`),
  CONSTRAINT `site_access_ibfk_3` FOREIGN KEY (`team_id`) REFERENCES `team` (`group_id`)
) ENGINE=InnoDB AUTO_INCREMENT=48 DEFAULT CHARSET=utf8

created time in 2 days

issue closedmarshmallow-code/apispec

Generate specification for routes based on YAML frontmatter attribute

First of all thanks for this awesome library 🌟

I was wondering if it's possible to control the generation of the specification based on a certain attribute in the frontmatter. For example, I can mark some routes as public/private and decide which ones to generate when calling spec.to_yaml():

@app.route("/random")
def random_pet():
    """
    public: true
    ---
    get:
      description: Get a random pet
      security:
        - ApiKeyAuth: []
      responses:
        200:
          content:
            application/json:
              schema: PetSchema
    """
    pet = get_random_pet()
    return PetSchema().dump(pet)

closed time in 3 days

aalvrz

starteddbeaver/dbeaver

started time in 14 days

issue openedmarshmallow-code/marshmallow-jsonapi

Using custom field for `id`

What is the correct way for using a different field to serialize the id field? I am dealing with SQLAlchemy objects that do not use an id field but rather a more verbose identifier like post_id for example.

I tried using data_key but it won't work:

class MySchema(Schema):
    post_id = fields.String("get_id", dump_only=True, data_key="id")

Using Function field works but I don't know if there is a better way...:

class MySchema(Schema):
    id = fields.Function(lambda obj: str(obj.post_id), dump_only=True)

created time in a month

issue closedaalvrz/scsj

Cannot update trial's TrialPeople

When editing a trial, TrialPeople can be added or removed using Select2. However when submitting to the controller, TrialPeople does not update.

closed time in a month

aalvrz

issue closedaalvrz/scsj

Improve Performance in trial's show view

Currently in a trial's show view, requests to the database are made for all the plaintiffs, the defendants, and each type of lawyer for each presentation in the trial.

closed time in a month

aalvrz

issue closedaalvrz/scsj

Add URL Slugs

Change current URLs using IDs to URLs that use slugs. This also applies for Devise paths.

closed time in a month

aalvrz

issue openedaws/chalice

Support JSONAPI `application/vnd.api+json` media type

The JSON API specification uses application/vnd.api+json as its designated media type. This should work just like application/json, but Chalice will not parse the request's JSON payload into a Python object:

@app.route("/someroute", methods=["POST"], content_types=["application/vnd.api+json"])
def someroute():
    request = app.current_request
    assert request.json_body is not None  # Fails

created time in a month

create barnchaalvrz/hourglass-api

branch : main

created branch time in a month

created repositoryaalvrz/hourglass-api

created time in a month

issue commentmarshmallow-code/apispec

Generate specification for routes based on YAML frontmatter attribute

@lafrech Maybe this example explains it better:

# This is a "public" endpoint that will be exposed in some docs generated from the final spec
@app.route("/random")
def random_pet():
    """
    public: true
    ---
    get:
      # ...
    """


# This is a "private" endpoint that we do not want to include in those docs generated from the spec
@app.route("/foobar")
def foobar():
    """
    ---
    get:
      # ...
    """

So if I only want to generate the YAML for endpoints with public: true. Basically I was looking for something like this:

api_spec.to_yaml(public=true)  # or some other way to filter based on the frontmatter

YAML Frontmatter reference: https://assemble.io/docs/YAML-front-matter.html

aalvrz

comment created time in a month

PR closed aws/chalice

Remove exception class name from HTTP error response

Issue #, if available: #1339

  • [x] By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
+3 -7

2 comments

4 changed files

aalvrz

pr closed time in a month

issue commentpython/mypy

IntEnum "is not indexable"

I am experiencing this with mypy==0.780, with similar errors:

"IntEnum" not callable
"IntEnum" is not indexable

When doing:

val = self.enum_class(value)
val = self.enum_class[value.upper()]
alexmv

comment created time in 2 months

startedscanapi/scanapi

started time in 2 months

issue commentmarshmallow-code/apispec

InvalidParameterError exception

@lafrech I read Components must be referenced by ID, not full path but I am still struggling to understand how to make this work...:

parameters:
  - name: some_id
    description: Some ID
    in: path
    required: true
    schema:
      type: integer
      example: 14875
  - $ref: "q"  # I believe this is what the doc refers to referencing by ID?

  responses:
    "401":
      $ref: "#/components/responses/UnauthorizedError"  # Weird thing is I can reference these by path and they work fine

I have registered the parameter component as:

api_spec.components.parameter(
    "q", "query", component={"name": "q", "description": "Apply search to query", "schema": {"type": "string"}}
)

But I still get the same error:

Traceback (most recent call last):
  File "build_api_docs.py", line 8, in <module>
    from app import app  # noqa
  File "/home/andres/gap/ssv-api/app.py", line 128, in <module>
    from chalicelib.routes.sites import site_routes  # noqa: E402
  File "/home/andres/gap/ssv-api/chalicelib/routes/sites.py", line 237, in <module>
    api_spec.path("/v2/teams/{team_id}/sites", resource=get_team_sites)
  File "/home/andres/gap/ssv-api/venv/lib/python3.8/site-packages/apispec/core.py", line 306, in path
    self.clean_operations(operations)
  File "/home/andres/gap/ssv-api/venv/lib/python3.8/site-packages/apispec/core.py", line 409, in clean_operations
    operation["parameters"] = self.clean_parameters(operation["parameters"])
  File "/home/andres/gap/ssv-api/venv/lib/python3.8/site-packages/apispec/core.py", line 365, in clean_parameters
    raise InvalidParameterError(
apispec.exceptions.InvalidParameterError: Missing keys ['name', 'in'] for parameter

I am using apispec==4.6.0

dpgaspar

comment created time in 3 months

push eventsystemsurveyor/api-docs

Andres Alvarez

commit sha ccba87f5607f33bec3047d415f8c7cc6bdb8f354

Move docs yaml file to repository root

view details

push time in 3 months

issue commentmarshmallow-code/apispec

Generate routes based on frontmatter attribute

But it shouldn't be too hard to achieve from user side. Just add a condition before your call to spec.path to check the "public/private" flag.

@lafrech That could work. But how can we check the public/private flag when calling spec.path? If this flag is set as an attribute in the yaml frontmatter.

aalvrz

comment created time in 3 months

startedmarshmallow-code/apispec

started time in 3 months

issue openedmarshmallow-code/apispec

Generate routes based on frontmatter attribute

First of all thanks for this awesome library 🌟

I was wondering if it's possible to control the generation of the specification based on a certain attribute in the frontmatter. For example, I can mark some routes as public/private and decide which ones to generate when calling spec.to_yaml():

@app.route("/random")
def random_pet():
    """
    public: true
    ---
    get:
      description: Get a random pet
      security:
        - ApiKeyAuth: []
      responses:
        200:
          content:
            application/json:
              schema: PetSchema
    """
    pet = get_random_pet()
    return PetSchema().dump(pet)

created time in 3 months

startedkeithrozario/Klayers

started time in 3 months