Issues (253)

psqlextra/datastructures.py (3 issues)

1 1
from typing import List, Tuple, Any
0 ignored issues
show
The import typing could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
2
3 1
from django.db.models.sql.datastructures import Join
0 ignored issues
show
The import django.db.models.sql.datastructures could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
4
5
6 1
class ConditionalJoin(Join):
7
    """A custom JOIN statement that allows attaching
8
    extra conditions."""
9
10 1
    def __init__(self, *args, **kwargs):
11
        """Initializes a new instance of :see:ConditionalJoin."""
12
13
        super().__init__(*args, **kwargs)
14
        self.join_type = 'LEFT OUTER JOIN'
15
        self.extra_conditions = []
16
17 1
    def add_condition(self, field, value: Any) -> None:
18
        """Adds an extra condition to this join.
19
20
        Arguments:
21
            field:
22
                The field that the condition will apply to.
23
24
            value:
25
                The value to compare.
26
        """
27
28
        self.extra_conditions.append((field, value))
29
30 1
    def as_sql(self, compiler, connection) -> Tuple[str, List[Any]]:
31
        """Compiles this JOIN into a SQL string."""
32
33
        sql, params = super().as_sql(compiler, connection)
34
        qn = compiler.quote_name_unless_alias
35
36
        # generate the extra conditions
37
        extra_conditions = ' AND '.join([
38
            '{}.{} = %s'.format(
39
                qn(self.table_name),
0 ignored issues
show
The Instance of ConditionalJoin does not seem to have a member named table_name.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
40
                qn(field.column)
41
            )
42
            for field, value in self.extra_conditions
43
        ])
44
45
        # add to the existing params, so the connector will
46
        # actually nicely format the value for us
47
        for _, value in self.extra_conditions:
48
            params.append(value)
49
50
        # rewrite the sql to include the extra conditions
51
        rewritten_sql = sql.replace(')', ' AND {})'.format(extra_conditions))
52
        return rewritten_sql, params
53
54 1
    @classmethod
55 1
    def from_join(cls, join: Join) -> 'ConditionalJoin':
56
        """Creates a new :see:ConditionalJoin from the
57
        specified :see:Join object.
58
59
        Arguments:
60
            join:
61
                The :see:Join object to create the
62
                :see:ConditionalJoin object from.
63
64
        Returns:
65
            A :see:ConditionalJoin object created from
66
            the :see:Join object.
67
        """
68
69
        return cls(
70
            join.table_name,
71
            join.parent_alias,
72
            join.table_alias,
73
            join.join_type,
74
            join.join_field,
75
            join.nullable
76
        )
77